[code deleted] Edited by moderator 01.12.2019 21:49 Don't use new Integer(), use Integer.parseInt() instead Thank you. I solved my problem, but diffrent way. I used : in.readLine().trim() instead of in.readLine() Edited by author 12.10.2008 21:20 My C++ solution was successful with 0.14 sec and 284k. Now i wrote the same algorithm in C#, and on 20 test i have ML on char[] separator = { ' ', '\n', '\r', '\t' }; string[] input = Console.In.ReadToEnd().Split(separator, StringSplitOptions.RemoveEmptyEntries); int k = 0; int n = int.Parse(input[k++]); ... And TL on int n = int.Parse(Console.ReadLine()); ... So, how I should read input data in C# to have AC? I got AC! In TL version i wrote in cycle string[] input = Console.ReadLine().Split(' '); int l = int.Parse(input[0]), r = int.Parse(input[1]); in AC version string input = Console.ReadLine(); int pos = input.IndexOf(' '); int l = int.Parse(input.Substring(0, pos)), r = int.Parse(input.Substring(pos + 1)); Whith this optimization program works 0.047 sec less, and i got AC :) #include <iostream.h> int main() { int mas[10000],x,k=0,p,sum=0,a[5000]; unsigned long int i,j,Q,N; cin>>N; for(p=1;p<=N;p++) { cin>>a[p]; } cin>>Q; for(x=1;x<=Q;x++) { sum=0; cin>>i>>j; for(p=i;p<=j;p++) { sum+=a[p]; } mas[k]=sum; k++; } for(p=0;p<Q;p++) cout<<mas[p]<<endl; return 0; } DEAR MASTER OF C++!!!DON'T COUNT SUM!!!INSTEAD OF COUNT SUM USE: a[k]=a[k]+a[k-1]; AND AT ANOTHER CYCLE for(x=1;x<=Q;x++) USE b[k]=a[j]-a[i-1]; cout<<b[k]<<endl; DON'T USE SUM! GOOD LUCK!!!!! Edited by author 15.03.2007 16:30 Just change cout << s[j] - s[i-1]; to cout << s[j] - s[i-1] << endl; and get AC!!! Edited by author 15.03.2007 00:21 I have got Crash (access violation) in test 20! Why? Is my source: Edited by author 11.02.2007 04:22 q<=100000!!! but r:array[1..10010]of longint Thenks, but I have Time limit exceeded in test №20 Try to think for a other solution for this problem. My new source but it not accepted: Edited by author 11.02.2007 04:22 But, and this source have time limit: Edited by author 11.02.2007 04:21 Use this apparoach. Stoge at a[i] the sum from a[0] to a[i]. Then the answer between e, q will be just difference between sums: a[q] - a[e-1]. Var a,b: array[0..10000] of integer; i,j: integer; n: integer; k: integer; Begin read(n); a[0]:=0; for k:=1 to n do begin read(a[k]); a[k]:=a[k]+a[k-1]; end; read(n); for k:=1 to n do begin read(i,j); b[k]:=a[j]-a[i-1]; end; for k:=1 to n do writeln(b[k]); End. 1 <= N <= 10000 = 10^4 0 <= Q <= 100000 = 10^5 !!! Really you don't need second array. Just read query and write result for it. Edited by author 18.12.2006 03:37 Time limit has been decreased to 0.5 sec. Accepted submissions have been rejudged, 87 of them changed verdicts to TL. Thank you! This problem becomes more interesting. I understand that i am using bad algo. Please show the way to write good algo. Thanks Easy. Calculate the sum quickly using a[j]-a[i-1] where a[i] is sum of all elements from 1 to i. can someone give me the test#20 cause i realy dont know where i can get WA I have WA on this test too. What algorithm do u use? I have just got AC. I only changed word to integer in my program. readln(n); a[0]:=0; for i:=1 to n do begin readln(m); a[i]:=a[i-1]+m; end; Edited by author 14.01.2006 15:45 type vector=array[1..10000]of integer; var a:vector; function Summa(i,j:integer):longint; var k:longint; S:longint; begin S:=0; for k:=i to j do S:=S+a[k]; Summa:=S; end; var i,j,k:integer; n:integer; q:longint; begin read(n); for i:=1 to n do read(a[i]); read(q); for k:=1 to q do begin read(i,j); if i=j then writeln(Summa(i,j)) else writeln(Summa(1,j)-Summa(1,i-1)); end; end. Why TimeLimite. It's easy. Your solution is O(N*Q). N=10^4, Q=10^5 => N*Q = 10^9 So it works about one minute on max-test. Please help! Why "Wrong Answer"? Var n,q,i,j : longint; s,e,suma : longint; a : array [1..10010] of longint; Begin readln(n); for i:=1 to n do readln(a[i]); readln(q); for i:=1 to q do Begin suma:=0; readln(s,e); for i:=s to e do suma:=suma+a[i]; writeln(suma); End; End. Var n,q,i,j : longint; s,e,suma : longint; a : array [1..10010] of longint; Begin readln(n); for i:=1 to n do readln(a[i]); readln(q); for i:=1 to q do Begin suma:=0; readln(s,e); for j:=s to e do suma:=suma+a[j]; {see i>>j} writeln(suma); End; End. but be time limit, Search for other way!!! With many thanks for help, for specified mistake. I have got Time Limit, and has remade algorithm and has finally got AC [code deleted] Вот текст программы. Почему система выдает ошибку компиляции? Может я этот термин не верно воспринимаю но по крайней мере у меня никаких ошибок компиляции нет Разъясните пожалуйста Edited by moderator 01.12.2019 22:33 Delete 'uses crt','clrscr','readkey'! Спасибо огромное. А то я понятия об этом не имел. Попробую без него на проверку отправить |
|