Common BoardTry this test case: 1 1 of vodka 1 2 of vodka Answer = 1 Thank you! I was being mad about this WA during the contest. :) Why answer is 1? He wants more than is in the shop, so he calls his wife and asks her. This means that the answer is 2. Or I misunderstood? Because he is letting our hero go in front of him, which is the main objective. Could anyone, please, explain it to me? I can't understand how to program it. I'm filling the "amount of name" for the storage in the shop and for the queue, then, for each human from the queue, I check, firstly, whether the shop has the product the customer needs to buy, and then, if the shop has it, I compare the amounts. But I have a problem in understanding the part where the shop doesn't have enough of the product and the customers switch places. Could anyone explain it to me? #include <stdio.h> int main() { int N, M; scanf("%d%d",&N,&M); long int res; if (N <= M) res = 2 * (N - 1); else res= 2 * (M - 1)+1; printf("\n%d",res); return 0; } Can't solve this promlem myself. I run your code online on some tests, it seemed ok. Check, maybe you go out of range in res? (know nothing about C) where is the problem #include<stdio.h> int main(void) { int a,b,sum; printf("a:"); scanf("%d",a); printf("b:"); scanf("%d",&b); sum=a+b; printf("Sum=%d",sum); return 0; } Edited by author 03.12.2015 01:58 And. Did you run it locally? Try please. You should have crash here: scanf("%d",a); scanf("%d",a); scanf("%d",&a); I really can't solve this task? Alwaus got TLE on test 39 :-( Can someone give me hint or ... As for me, simpliest way is to use assembler instructions. There are some optimizations like this: Bad code: for (x = 0; x < W; x++) for (y = 0; y < H; y++) A[y][x] = 1; This code works much faster than previous one: for (y = 0; y < H; y++) for (x = 0; x < W; x++) A[y][x] = 1; Still nothing :-( This problem is driving me crazy!!!! There is one optimization, that speeds up simple solution in about 5 times. So, keep on solving. Please send me some hint!! a:array[1..4,1..10000] of word; for k:=1 to 4 do for i:=1 to n*m do begin if i mod m=0 then readln(p1,p2) else read(p1,p2); a[k,i]:=(p1-1)*m+p2; end; this be fast i think it more faster :) a:array[1..4,101..10100] of word; for k:=1 to 4 do for i:=1 to n*m do begin if i mod m=0 then readln(p1,p2) else read(p1,p2); a[k,i]:=p1*m+p2; end; Вообще если про скорость проверка if i mod m=0 все тормозит k++; if (k==m){ readln(p1,p2); k=0; } else read(p1,p2); надо так и еще очень ускоряет (покрайней мере у меня разные там битовые сдвиги) I wrote a starightforward O(N*M*S) solution without any optimizations and got AC. Had TLE in java. Rewritten in C -> AC. I had a program like that: while (x <= b/2) { .... x += dx } but it will fail test 1 1 100 (the last piece won't show). Changed to while (x <= b/2 + 0.000001) { .... x += dx } Got AC! I Solved this problem, by transforming x and y into every system and search for the longest common substring. But I am interested in another Ideas, better than mine, except brute force. it isn't necessary to search LCS (O(|x|*|y|)), you can check only what y is subsequence of x, so it will be O(|x|+|y|) Edited by author 30.08.2009 16:00 Verification of this fact is O(log(max(x,y))) base = 2..1000 bruteforce, base > 1000 think a little :)) Нас просят найти количество непустНых палиндромов. whats test #1?? Test case #1 is usually from the sample. Input 5 3 3 2 2 3 Output 3 Okay! Haskellers understand here! If you need use getContents for input you have two options for local executions on linux or unix environments: 1) Create file with inputs and execute on command: cat input.txt | ./main(haskell program) 2) On terminal execute the program, copy and past your entry for program and execute <CTRL>+D for EOF. That form the program execute and complete your operations. I'm let that here only for informations for others new for Haskell. Thank you, Hygens ################################################################################### Hi, haskellers on duty! I'm attempting test the script haskell on mine environment for "1001 - Reverse Root" problem using the same code exposed on Guide session for Haskell but here freeze without response on display. My environment is based on Linux Mint 16.04 with GHC 7.10.3. Exists any detail that I have passed or I have update that script for that version of Haskell?! Not occure any error on environment simple that freeze without response for long time and I break the execution. Some can help on that or had same proglem for ubuntu or mint?! Thank you, Hygens Edited by author 28.12.2016 18:59 Edited by author 28.12.2016 19:30 what is the answer for the following test bbbb wwwb wbwb wbbb my AC code shows that answer is 7, is that right? My AC program show answer 5 coordinates: 1:1, 1:2, 2:2, 2:3, 1:4, board becomes all black Edited by author 07.06.2011 00:10 yes that's what i'm talking about, my code fails on that test, but i got AC. i think it need to add test That to admins ;) What algo you're used? Your different submissions takes significand different time. Looks like random-based algo ) Edited by author 07.06.2011 00:26 i used recursion, those ones which execution time was higher had just deeper recursion My non-Accepted program gives 5. I have WA#11 needn't all 2^16 search, divide it two part each 8 bit. Can you please share some tests? Answer was correct on every test from forum, still can't pass test 14 + implemented all the hints, including rounding with 0.5000000001 and searching near the optimal values :( Thanks in advance! Edited by author 28.12.2016 02:12 my program calculate: Input: ====================================== String str = "10.23\n" + "0\n" + ".04\n" + "1\n" + "-0.051e0\n" + "1\n" + "1.1e30\n" + "10\n" + "-1.1E-30\n" + "1\n" + "2468097632.1358642324268913e-2\n" + "20\n" + "e23\n" + "3\n" + "1 e3\n" + "1\n" + "-7293874219874982174982174987321e-18446744073709551616\n" + "10\n" + "#1234\n" + "3\n" + " 12.0\n" + "3\n" + "2E-1\n" + "3\n" + "-\n" + "2\n" + ".e1\n" + "2\n" + "#"; ====================================== Output: ====================================== 10 0.0 0.0 1100000000000000000000000000000.0000000000 0.0 24680976.32135864232426891300 Not a floating point number Not a floating point number 0.0000000000 Not a floating point number Not a floating point number 0.200 Not a floating point number Not a floating point number ====================================== It's correct. why wrong test-12? try also -7293874219874982174982174987321E-18446744073709551616 10 -7293874219874982174982174987321E-4294967296 10 -7293874219874982174982174987321E-65536 10 -7293874219874982174982174987321E-256 10 9126492316491641269352615215701236589213658621356281376589216562319562396592381659862195621281E-190 100 1234E-000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002 2 # (note that last two - is long strings. That only displayed in this forum as several lines Edited by author 27.05.2011 21:51 Input: ============================= String str = "-7293874219874982174982174987321E-18446744073709551616\n" + "10\n" + "-7293874219874982174982174987321E-4294967296\n" + "10\n" + "-7293874219874982174982174987321E-65536\n" + "10\n" + "-7293874219874982174982174987321E-256\n" + "10\n" + "9126492316491641269352615215701236589213658621356281376589216562319562396592381659862195621281E-190\n" + "100\n" + "1234E-000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002\n" + "2\n" + "#"; ================================== Output: ================================== 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009126 12.34 ================================== It's correct. Edited by author 30.05.2011 14:22 There are some more examples? try 9E-9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 100 -1E-1 5 send to me your solution at aterlux @ mail . ru if you want, I'll take a look Edited by author 30.05.2011 17:20 Input: ============================= String str = "9E-9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n" + "100\n" + "-1E-1\n" + "5\n" + "#"; ================================== Output: ================================== 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0.10000 ================================== It's correct. I have resolved! It's my bug. My program has not processed this case: ====== +.0 0 ====== This example has this answer: ====== 0 ====== But my program has this answer: ====== Not a floating point number ====== I passed all the above cases including the +.0 0 but still WA. I had WA#3 because of how I was reading the input in C: while (gets(buff) != NULL) { int i = 0; while (buff[i] != '\0') { // process char by char i++; } } Changed to: while ((c = getchar()) != EOF) { // process char by char } And it works AC!!! Hello! Can somebody tell me if there is a faster algo than O(Q^2*N)? My algo works pretty fast, but I wondered if there is a better way to do it. My solution Q*N, lol Or no I'm not sure Edited by author 11.03.2016 21:50 Edited by author 11.03.2016 21:50 My algo is fills dp[vertex][presaved edges] array (result is dp[1][Q]), where total loops N^3/6 < 2*10^5. There maximum presaved edges = Q, but more vertexes have less edges than Q. Let edges[v] - number of edges of v vertex. So there O( N * sum( edges[ v ] * ( edges[ v ] + 1 ) / 2 ) ) = O( N^3 / 6 ). you must write "not eoln" no "not eof" and you'll got AC!! THANK YOU!!! Very much! Had WA1. Got desperate, rly, can't find any mistakes. Can't believe it was it. Change this tiny word and get AC! Still, why it makes such difference? #include <iostream> #include <vector> #include <string> int corrections = 0; bool words_match(const std::string& w1, const std::string& w2); void process_word(const std::vector<std::string>& dict, const std::string& word); int main(){ std::vector<std::string> dictionary; std::string curr_dict_word; std::getline(std::cin, curr_dict_word); while(curr_dict_word != "#"){ dictionary.push_back(curr_dict_word); std::getline(std::cin, curr_dict_word); } char c; std::string cword; while(std::cin.read(&c,1)){ if('a'<=c && 'z'>=c){ cword.insert(cword.end(), c); continue; } else if(!cword.empty()){ process_word(dictionary, cword); cword = ""; } std::cout << c; } if(!cword.empty()){ process_word(dictionary, cword); } std::cout << corrections << std::endl; return 0; } bool words_match(const std::string& w1, const std::string& w2){ if(w1.length() != w2.length()){ return false; } bool mismatch = false; for(int i = 0; i < w1.length(); ++i){ if(w1[i] != w2[i]){ if(mismatch){ return false; } mismatch = true; } } return mismatch; } void process_word(const std::vector<std::string>& dict, const std::string& word){ for(int i = 0; i < dict.size(); ++i){ if(words_match(dict[i], word)){ std::cout << dict[i]; ++corrections; return; } } std::cout << word; } Please don't post your solution here. Maybe there is just small limits or not right topic?? |
|