| Show all threads Hide all threads Show all messages Hide all messages |
| Why this DP solution doesnt work? | Dmitriy | 1353. Milliard Vasya's Function | 13 Feb 2018 06:22 | 8 |
I thought that this problem is so easy. After many tries to solve that I should say: that is not so easy and I cant solve it! Please, if you DP-master tell me where I'm wrong. So, the state is dp[sum][length] += dp[sum - digit][length - 1], for each digit 0..9. The base is dp[1..9][1] = 1. I've got WA#10: My program for 10 output: 43756 (correct answer: 43749) I can't find a little bug ;( [code] for s := 1; s <= S; s++ { for l := 2; l <= 9; l++ { for d := 0; d < 10 && s - d > 0; d++ { if dp[s - d][l - 1] == 0 { continue } dp[s][l] += dp[s - d][l - 1] if d == 0 { dp[s][l]++ } } } } [/code] You don't need to store previous positions: for (int position = 2; position <= 9; position++) for (int sum = 81; sum > 0; sum--) for (int digit = 1; digit <= 9; digit++) if (sum >= digit) ways[sum] += ways[sum - digit]; because you have to start l at one and eliminate continue and s - d >= 0 No. You are wrong here. I've found my error, it was a dp base. Thx for all. Guys, what are you doing in New Year? Hahaha |
| Wrong Answer || Compiler: GCC 7.1 | Meraj al Maksud | 1409. Two Gangsters | 13 Feb 2018 04:59 | 3 |
I don't understand what's wrong with my code. Help me pls. Thnx in advance. #include<stdio.h> int main(){ int L, H; scanf("%d%d", &L, &H); printf("%d %d ", 10 - L, 10 - H); return 0; } It said not more than 10 cans... thus there could be less than 10 cans Once Harry and Larry shoot a common can... you gotta consider that too... |
| What is in 4 test? | Ilya | 1875. Angry Birds | 13 Feb 2018 02:19 | 1 |
|
| WA 5...Please give some tests..Thx~ | Scau_Ly | 1508. Japanese Puzzle | 11 Feb 2018 18:38 | 2 |
I use Dynamic Programming..and i made several tests myself, my code could calculate the right answer = =...sorry for my poor English Simple tests: 1) 5 2 2 2 ????? ans:XX.XX 2) 4 2 2 2 ???? ans:Impossible 3) 15 3 2 1 2 ??X?.?.......X? ans:.?X?.X.......XX 4) 15 5 2 1 2 1 2 ??X?.?.X.?.?.X? ans:Impossible 5) 5 0 XXXXX ans:Impossible 6) 5 3 1 1 1 X.X.X ans:X.X.X 7) 5 2 1 1 .?.?. ans:.X.X. 8) 18 5 3 1 1 3 1 .???.X?.??..?XX?.? ans:.XXX.X..??..?XX?.X |
| asm tips | Orient | 1369. Cockroach Race | 11 Feb 2018 13:26 | 2 |
Make two separate arrays for x and y coordinates of cockroaches. Don't use horizontal instructions in tight loops. Perform all the develop and debug in 32-bit mode (evidently GCC/Clang on server has -m32 key). x86-64 has RIP-relative addressing, there would be bottlneck when you go back to 32-bit build and try to backport from 64-bit one. First loop for each sweet is straitforward. Don't use `displacement(base,index,scale)` addressing. Always run all over the `base` part. Finally it may give about a couple of hundred ms. In second loop for each sweet you may use BSF instruction to get least significant bit offset (remeber, judge runs on Sandy Bridge arch). Use LEA to calculate simple index arithmetic. Here is mine: size_type R = 0; asm ( "vbroadcastsd %[dmin], %%ymm5;" "dloop:" "vcmpgt_oqpd %[d](,%[i],8), %%ymm5, %%ymm6;" "vmovmskpd %%ymm6, %%eax;" "test %%eax, %%eax;" "jz rnext;" "rloop:" "bsf %%eax, %%edx;" "lea 1(%%edx,%[i]), %%edx;" "mov %%edx, %[results](,%[R],4);" "inc %[R];" "lea -1(%%eax), %%edx;" "and %%edx, %%eax;" "jnz rloop;" "rnext:" "add $4, %[i];" "cmp %[M], %[i];" "jl dloop;" : [R]"=b"(R) : [d]"m"(d), [dmin]"m"(dmin), "0"(R), [results]"m"(results), [M]"r"(M), [i]"c"(0) : "cc", "memory", "%eax", "%edx", "%ymm5", "%ymm6" ); Custom IO gives about 300+ ms. I hope M*N solutions finally will loose their ACs someday (at least until hardware will be updated to AVX512-compatible). It turns out, that there are possible two way to solve this problem (both M*N) in addition to naïve one (1400ms). 1.) Read all sites, then for each query point do find all the preliminary neighbours using float coordinates (it is almost two time faster in terms of membory bandwitdth, then if use double). This is a "float" sieve. Then for all sites passed "float" sieve perform similar "double" sieve. It get about 500ms (for me from 1.45s to 950ms). Test #16 is still hardest. Prefetch instructions in long runs gain up to 100ms. First loop (precalc of squared float distances) can be unfolded 4 times by query points (vbroadcastss from fixed memory location works fast in loop, you should not occupy dedicated ymm register for these). Second loop, where squared distances compared against least distance (+ eps of course), found in previous loop, can be unfolded 4 times (you can occupy all 32 bit of some register using bit shift (ror, rol) after vmovmskps). I think it allow to better utilize branch prediction mechanism. This approach can be beaten by simple test: cloud of sites in one corner in 10x10 square and cloud of query points in opposite aslo in 10x10 square both in general position (not matters much). Or wiser: query points placed on quarter of circle with center in one corner and radius of 20000, sites on another quarter of circle with center in the same corner and small radius or vice versa. Or even: two distant strait lines: one with query points and another with sites. 2.) You can solve the problem in single loop using just doubles with randomization. If your random numbers hit right sites, then you can probably make even fastest solution (but it is too improbably). I can't find counterexample for this randomized approach. I am very interested in Progbeat's solution details. It seems (by memory consumed) he used approach very similar to mine. It would be great if we'll exchange our solutions somehow =). |
| Как вибирать из двух одинаковых по длине ответов? | Bazeev Damir`~ | 1651. Shortest Subchain | 11 Feb 2018 10:40 | 1 |
17 1 2 3 4 5 6 7 2 8 9 5 10 8 9 11 3 9 1 2 8 9 1 2 3 9 ?????????????????????????????????????? |
| I got WA on test 9, please give me some sample data, I'm desperate | Dan Stefan | 1043. Cover an Arc | 11 Feb 2018 04:01 | 7 |
I suspect rounding errors or something I have WA#9 too. The program seems to be right. Who can help me? I think, that your calculations not so are exact, as that is demanded with a problem. Try to not use intermediate values (for example radius etc.). Re: Gheorghe Stefan 31 Jan 2005 18:27 you have all tests on timustests.4t.com Re: UNKNOWN_LAMER 31 Jan 2005 22:22 Thank you very much. You were right about my bug. I have just change in my C++ code ceil(x) to ceil(x-eps) and floor(x) to floor(x+eps) and got AC!
Hey, UNKNOWN_LAMER! Do I know you from somewhere? Re: estefy 11 Feb 2018 04:01 je Edited by author 11.02.2018 04:58 |
| Solution | 2ch | 1268. Little Chu | 11 Feb 2018 01:49 | 1 |
|
| AC in 0.015 | Aditya Singh | 1118. Nontrivial Numbers | 10 Feb 2018 15:29 | 2 |
[code deleted] Edited by moderator 19.11.2019 23:40 Hi, Very good solution! Just one note, it doesn't affect AC, but: In D+=(i+N/i); if (i == N/i) you don't need to add both i and N/i, but just i. In this case result of check(N) will be 100% equal to triviality(N) in all cases. |
| for n = 10, k = 2, ans = 89. How?? | iOli | 1009. K-based Numbers | 10 Feb 2018 08:18 | 1 |
|
| Test 26 | Vitaliy Herasymiv | 1866. Poetic Foot | 9 Feb 2018 20:43 | 3 |
Test 26 Vitaliy Herasymiv 15 Oct 2011 15:07 Please, check test #26, it seems to be incorrect. Oh no, that test is correct! I got AC. |
| WA 4 | Bazeev Damir`~ | 1651. Shortest Subchain | 9 Feb 2018 19:53 | 1 |
WA 4 Bazeev Damir`~ 9 Feb 2018 19:53 |
| Test 6 | Shorekh | 1131. Copying | 9 Feb 2018 04:11 | 2 |
Test 6 Shorekh 20 Oct 2016 22:48 Re: Test 6 Siroj Matchanov [TUIT] 9 Feb 2018 04:11 Whoever gets Wrong Answer at 6th test, try to change your way of finding the power of two. My solution got WA#6 when I calculated power of two this way: power = ceil(log(x)/log(2)); Better calculate it by multiplying it. |
| what about Ramanujan's 1729 | Adkham | 1349. Farm | 8 Feb 2018 19:27 | 1 |
I remember once going to see him when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I hoped it was not an unfavourable omen. "No," he replied, "it is a very interesting number; it is the smallest number expressible as the sum of two cubes in two different ways." G.H.Hardy 1729 = 1^3 + 12^3 = 9^3 + 10^3 |
| what is wrong with my code ??? | Adkham | 1110. Power | 8 Feb 2018 02:23 | 1 |
#include<iostream> #include<cmath> using namespace std; int func(int k, int n, int m) { if(n == 0) return 1; else return func(k, n-1, m)*k%m; } int main() { int n, m, y, x, i = 0; int b; bool flag = true; cin >> n >> m >> y; if((n >0 && n < 999) && (m > 1 && m < 999) && (0 < y && < 999)) { while(i < m) { x = func(n, i, m); if(x == y) { cout << i << ' '; flag = false; } i++; } if(flag) cout << "-1"; } else cout << "-1"; return 0; } Edited by author 08.02.2018 02:25 Edited by author 08.02.2018 02:27 |
| Solution is pretty easy | 2ch | 1109. Conference | 7 Feb 2018 21:51 | 1 |
Firstly, the problem asks to find number of edges in minimum edge cover Secondly, the number of such edges plus the number of maximum matching equals to number of vertices, that is N + M Thirdly, you can find the number of max. matching easily with dfs-like algorithm (you can find code online). The answer is N + M - (number of max. matching) |
| what is the 30 test | Bekzat | 1820. Ural Steaks | 6 Feb 2018 23:31 | 3 |
|
| TLE #21 | JohnDarkman | 2102. Michael and Cryptography | 6 Feb 2018 19:25 | 1 |
TLE #21 JohnDarkman 6 Feb 2018 19:25 I get TLE on 21 test. What can you advise? |
| Example Testcase | Khanhhuy_19 | 2018. The Debut Album | 6 Feb 2018 18:47 | 2 |
i think 212 in the Example test is wrong cause we have 2 remix of "I miss you" when the most remix that we can reach is 1 . Edited by author 21.01.2018 23:56 It says: "in a row". It means that there can be any number of remixes of each song, the most important part it that the number in each row doesn't;t have to exceed a for 1st and b for 2nd |
| Test | BdE | 1846. GCD 2010 | 5 Feb 2018 22:15 | 1 |
Test BdE 5 Feb 2018 22:15 in: 9 + 10 + 10 + 10 - 10 - 10 + 5 - 10 - 5 + 123 out: 10 10 10 10 10 5 5 1 123 GL. Sqrt decomposition works fine in this problem. |