Common Boardis operations of int64(pascal) slower than long long(c++)? I really optimized my prog to got AC(I write at Pascal). Please say how you did that on Pascal my algo O(N^3*logX) It work fast on my computer, but not on Timus :( Me and my friend had exactly the same algorithm and optomization but my program needs 1.7 and his needs 0.3secs (we both use C++) It is very hard to solve it in Pascal, so use C++ :) or rewrite program several times. It appeared, that FreePascal 2.0.4 compiler, which is used on Timus Online Judge, is extremely slow at arithmetical operations, especially on Int64-operands. "Mod" and "*" operations on Int64 are very slow. We did not expect such a thing, and we are sorry. Anyway, the jury HAS correct Pascal solution, which passes the timelimit (2 seconds), so it is a question of justice only, not of jury mistakes, problem incorrectness and so on. Now the timelimit is 3 seconds, and it is more than enough to solve this problem on Pascal without special optimization trick. My straightforward solution works exactly 2 second: http://acm.timus.ru/status.aspx?space=1&num=1518&pos=1383115 The problem will be rejudged soon. The performance of FreePascal 2.0.4 compiler in comparison with Delphi 7 compiler (dcc32 15.0) is under inverstigation. If Delphi appears to be faster (and it seems to be true), it would be added on Timus Online Judge. If you know the fastest Pascal compiler, please, tell us. It will be fair for Pascal programmers, because the fastest Intel C++ Compiler is used for C++. Edited by author 19.12.2006 21:43FreePascal generates very bad code for int64 multiplicatons. I use Delphi 7.0 and on my computer (AthlonXP 2200) my prog works 0.9 sec in worst case, but on Timus the same prog works 2.093 sec. I got AC in 1.261 sec with rewritng multiplication on Assembler. 19 authors get AC instead of TLE. 7 of them increase their score by 1 problem! My algo is also N^3*log(X), but not accepted in C++. how to solve it? Time limit in test case 13. anyone helps me ? Edited by author 20.12.2006 01:17 My solution is also O(logX*N^3) but my program written on Java works so slowly... for example, It works about 6 seconds on test 100 268435455 268435455 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 I can't even imagine how to solve it without rewriting solution using another language... Edited by author 08.01.2007 19:20 Since the matrix consists of only zeroes and ones, you can perform half of multiplications using just +, - and >= via 32bit types. Perform only squaring via __int64 and %. This helped to make my 2.9 sec C++ solution running at 1.5 sec. Yeah... I almost wrote DP :))) it's waaaay easier. Thanks! :) Can any one tell me how to solve this problem using greedy approach pls..? Initially values till max=0 are reachable. If next coin is higher than max+1, then the answer is max+1. Otherwise max is boosted by its value (that is, values 0...max+ai are reachable). Proceed until you find a hole or you run out of coins. I can't find my mistake. Can you sent me test#2 to <<mihran91@mail.ru>>? this is my code # include <iostream.h> # include <math.h> main () { double dx[50001],dy[50001]; int i,n; double x0,y0,xk,yk,x1,y1; cin>>n; for(i=0;i<n;i++) cin>>dx[i]>>dy[i]; dx[n]=dx[0];dy[n]=dy[0]; xk=0.5*(dx[0]+dx[1]); yk=0.5*(dy[0]+dy[1]); x1=dx[0]-dx[1]; y1=dy[0]-dy[1]; y0=yk+0.00000001; x0=(xk*x1-y0*y1+yk*y1)/x1; double ma,mb,a[2],b[2],det,otv=0; A: for(i=0;i<n;i++) { a[0]=dx[i]-x0; a[1]=dx[i+1]-x0; b[0]=dy[i]-y0; b[1]=dy[i+1]-y0; ma=sqrt(a[0]*a[0]+b[0]*b[0]); mb=sqrt(a[1]*a[1]+b[1]*b[1]); det=a[0]*b[1]-b[0]*a[1]; if(det>0) otv+=acos((a[0]*a[1]+b[0]*b[1])/(ma*mb)); else otv-=acos((a[0]*a[1]+b[0]*b[1])/(ma*mb)); } if(fabs(fabs(otv)-6.28318530717)>0.00001) { otv=0; y0=yk-0.00000001; x0=(xk*x1-y0*y1+yk*y1)/x1; goto A; } if(otv<0) cout<<"cw"; else cout<<"ccw"; return 0; } Don't write such message to admins. I think they don't mail to you anything. May number C has more digest, then numbers A and B? Yes, but that does not cause many problems. Just prepend A and B with leading zeroes which you will never change. I think that answer is amount of digits |A+B-C| Sorry, it's incorrect Edited by author 03.01.2007 23:51 It's impossible to know all nice formulas. I used DIVIDE AND CONCURE for which problem is excellent but Challenge-team don't allow us recursion and converting the algorithm to iteration made it less clear. To compare different algo some test using my Ac program here: 99 1 300 2 1111 66 7777 12 1111 66 77777 46 100 1 9999 61 99 99 1000 -1 1 80 201 12 4 8 99 15 345321543 123215642 876543129 21 My program pass all this tests. However i got WA6... :( Be must careful with first digits. They can't be =0. But if digit only one? Acording to problem statement it also <>0 because it also first. But I gueesd that for 1 digit it can be =0 and have AC. Can anybody give me a hint how to solve it? Most simple to understand- use Divide and concure method. You solve the problem separetely for 1 and 2 halfs of strings and add optimal results. Blocs must be agreeed by means of common Carry fron 2 to 1. Exit from recursion when size of block=1,or only one digit. It this case use optimization by full search. Shortly to say it is problem from positioning number systems. Continuation. Alternative method- dynamic programming. We start witn 1-digits blocs. Let N- numder of them. We solve the problem for each one and store result in array. After we buld N/2 blocs with size 2 using array for 1-blocs. Result write to the same array. And so on: building blocs, containing 4,8,.. digits. Finally we will have one block with size N and array[0]- the answer. To agreed blocs on each stage array must depend also on in and out carries of each block. Edited by author 25.01.2007 00:15 Edited by author 25.01.2007 00:15 Thank you for explanation! Or this problem can be solved using DP digit by digit, without any blocks) =) very thanks to all who give sample tests and explain recursive algorithm!!! At last I've got AC My AC solution never allows first digit to become zero, even for one-digit-long numbers. Also, BE AWARE that there are test(s) with leading zeroes, at least test #15. 345321543 123215642 876543129 21 that test is wrong. correct answer is 20. My AC solution gives 21 as well. Check if you do not allow carryover past leading digit, leading zero, etc... svr, thanks for your tests! They helped me to find a bug :) (I could allow leading zero for the 3rd number) please, tell me, what type of array i must take? i took MLE on this : array[1..125000] of int64; But I get memlimit on 7th test , but used longword Unfortunatelly you can't conserve all elements simultanionsly. Try to use ideas of heap sort or use priority_queue<int> if you are C++ programmer :-). What's the answer for ------------------------------ 30 8 15 16 19 17 18 20 21 27 30 29 28 26 25 24 23 22 14 13 12 11 10 5 4 3 2 1 6 7 8 9 ------------------------------ 30 10 15 16 19 17 18 20 21 27 30 29 28 26 25 24 23 22 14 13 12 11 10 5 4 3 2 1 6 7 8 9 ------------------------------ my answers are 59165 for test case 1 and 51963 for test case 2 The last line of the input file in the example reflects that the right limit of the black interval is 47. But the white interval in the output file begins with 47. How can it be?? If one supposes that limits of these intervals are not included then they are shouldn't be included in the 3rd and the 4th lines either. Then the white interval ends with 299 and another one begins with 301. But the answer would be "301 633" this way. What is the right way to understand the terms of this problem? It's the axis we are painting, therefore you have to think continuous interval . I think if the range is 1 2, then all to left of 2 up to 1 is painted, and all to right is unchanged. Can you give me the test which answer is =0. And I got WA#4 please give me the tests. Edited by author 25.06.2008 12:15 Edited by author 25.06.2008 12:15 I have WA (5) but I think there is no such input (if all numbers contain 1,2,3 and 4) New tests were added. 112 authors lost AC verdict. () 1 ?? () ->0 ??? "A string a is a cyclic shift of a string b if a and b have the same lengths and a consists of some _(possibly empty)_ suffix from b followed by a prefix from b." I dont understand ur explaining . Can U explain it(cyclic shift) with some examples "possibly empty" has been emphasised. so every expression is a cyclic shift of itself. () leads to two cyclic shifts: () and )(. Only () is valid bracket sequence, so the answer is 1. Are you sure that 23th test is correct ? I've got WA with 24... but some tests were added, so it's probably an old 23 No, it's correct. I had some stupid mistake. You should remove Black figures and White too. A good hint indeed for WA3! =))) Can you please recheck the problem statement because of disparity of English and Russion versions. Coordinates of cockroaches are integer without any limitation in russian version, and english version says that all cordinates are real with some restriction on it. Edited by author 16.06.2007 15:51 And the next sentence is missing in Russian version: "The distance between any two cockroaches is not less than 10−3. Also the distance between any two sweets is not less than 10−3." Help me! Program Contest_B; Var I, R : LongInt; Ans : Int64; Tmp : Extended; Begin ReadLn(R); If R = 1 Then Ans := 4 Else Begin Ans := 0; For I := R - 1 Downto 0 Do Begin Tmp := Sqrt(Sqr(R) - Sqr(I)); If Tmp - Trunc(Tmp) <= 1E-9 Then Inc(Ans, Trunc(Tmp)) Else Inc(Ans, Trunc(Tmp) + 1); End; Ans := Ans * 4; End; WriteLn(Ans); End. >Tmp := Sqrt(Sqr(R) - Sqr(I)); Overflow of longint type for r>32768. And according to the statement r<=100000. Дело не в этом longint ограничен 2^31-1>2000000000 а вот inc не работает с типом int64 For people who will solve this problem in the future: it is possible to use floating point arithmetics and get AC with n^2*logn solution. who can give me some test data? My program is wa #19? puzzling ? RTFM =) What is RTFM? I the beginning programmer and I know only one language... It is Pascal RTFM = Read The F...ing Manuals =) Read the FAQ - there you'll find out how to learn that an input stream has ended (in pascal these are the functions eof/eoln/seekeof/seekeoln) I know this functions. All of them are intended for work with files! But my program should not use files, and should read from the keyboard and show on display... Or for this problem there is an exception? Read in the FAQS : How to write Pascal solutions You are not right. These functions are intended to work not with files, but with input/output streams instead, which you can connect with keyboard/monitor. RTFM =) while not eof do begin ... end; (0)+(0)=(0) or 0? There is always period, so the answer is (0) Edited by author 22.09.2007 19:17 And that happens to be test 34. I had CRASH there as I've put a trap on such case before submission. Lucky me :) Eventually, removing that trap gave me AC. So just treat 0 like any other digit, do not care about leading zeroes. |
|