|
|
Common BoardMaybe there is just small limits or not right topic?? My solution is O(n^2*logn) and works ~1.7 seconds. But some people got AC in .078. How? I solved it with next algo: I bruteforce all possible connections (if graph consists of several not connected parts) and then add some edges for Euler path with greedy. Of course its right algo, but some complicated (i think). Does anyone knows more simple one? Only use buffered i/o )). Подскажите кто нибудь что я делаю неправильно? import java.util.*; import static java.lang.Math.*; public class Sqrt{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.println(sqrt(in.nextInt())); } } The main method I followed was to first compare two of the arrays and extract the similar values in another array. I then compared that array with the third array, and updated the counter each time there was a match in eigenvalues. This method avoids comparing all the arrays together, and hence takes up less time. So in essence number of operations reduces to O(2*N^2) instead of O(N^3). However, more sophisticated algorithms like binary search are more effective. But still I include this method for people like myself, who are new to algorithms. Hope it helps someone. Thank you! Did as you said and get Accepted)) 0.046 seconds (FreePascal) Any hints for this problem? Try solve 2 sub problems when dodecahedron on odd position and not. var j,i,n:longint; m:array of real; begin n:=1; while not seekeof do begin read(j); SetLength(m,n); m[n]:=sqrt(j); inc(n); end; for i:=n to 1 do writeln(m[i]:0:4); end. 1. chek type of j. You may have input = 10^18, but max in longint ≈ 2*10^9. 2. Write size of array. 2. Don't know what this is: SetLength(m,n); delete this nah) 3. for i:=n to 1 do |=> for i:=n downto 1 do 4. Chek why for this input: 9. your output is 0.0000 3.0000 little change your programm and get AC)) Edited by author 18.12.2016 03:29 I don't understand what's wrong in my program. Give me test 9 please is there something invalid in test cases?? Help! What is in the test 26? -- use fread | fwrite; -- do not use << if >> statement or minimize it; -- minimize div and mod operations ( % , / operators); -- instead of % , / operators may to use pre-calculated arrays. -- and last, need lucky :) 10^6 numbers --> input file size ~4 Mbytes, and output file size ~1 Mbytes. MY PC i-core 3 , 3 GB RAM, gcc 5.4.0 with option: g++ -Wall -O3 -std=c++14 reads/writes took 6-9 milliseconds. So there need something magic tricky to solve this with time < 1 milliseconds !!!!! I got 0.001s AC!! buffered i/o helped me. Your program ate 12 Mb memory. So I suppose you are reading the whole numbers and then do addition. It isn't necessary. It's possible to add numbers digit by digit (yes, from high digits to low) without any arrays usage - 0.3s even using scanf/printf. And yes, use fread/fwrite. Edited by author 13.12.2016 22:15 Forgot to sort the updates :) I am getting WA in 22nd case! I cant find my mistake. Can someone help me ? Try this: 20 1 00000000100000000001 Answer: 0 1 15 Please could anybody give me the test case? Thanks If you are using int(s[i]) to get the representation for any alphabet, you may need to enlarge your counting sort table and counting sort iteration limit. I thought 200 was enough for latin alphabets, but actually I tried several times and succeeded at about 1100. I don't even know why... char s[16384] ; unsigned n = 0; // AC 0.001s with this code. for(int c = std::getc(stdin); c != EOF; c = std::getc(stdin)) s[n++] = c; // and AC 0.015s with n = fread(s,1,sizeof(s)-1,stdin); code. // I'm wonder that the std::getc faster than fread!! System.out.printf("%.6f\n",(t+s+ss[i])/2d); It have solution with no arrays, lol) And (t+x+si)/2.0 right too, but some simply) I know, that my English bad( |
|
|