| Show all threads Hide all threads Show all messages Hide all messages |
| Please help me, Crash #19 | Dijkztra | 1434. Buses in Vasyuki | 27 Jun 2012 01:06 | 2 |
Can someone help me to debug this C++ code? It got crash at 19th test-case. #include<cstdio> #include<vector> #include<queue> using namespace std; vector<int> p[1005]; vector<int> idxs[10005]; int dist[10005]; int bef[10005]; queue<int> q; void print(int n) { if(n!=-1) { print(bef[n]); printf("%d ",n); } } int main() { int n,m,c,d,awl,akh,tmp; bool sudah = false; scanf("%d%d",&m,&n); for(c=0;c<=n;c++) { dist[c] = 10000000; bef[c] = -1; } for(c=0;c<m;c++) { scanf("%d",&d); while(d--) { scanf("%d",&tmp); p[c].push_back(tmp); idxs[tmp].push_back(c); } } scanf("%d%d",&awl,&akh); dist[awl] = 0; q.push(awl); while(!q.empty()) { tmp = q.front(); q.pop(); n = idxs[tmp].size(); for(c=0;c<n;c++) { m = p[idxs[tmp][c]].size(); for(d=0;d<m;d++) if(p[idxs[tmp][c]][d]!=tmp) if(dist[p[idxs[tmp][c]][d]] > dist[tmp]+1) { dist[p[idxs[tmp][c]][d]] = dist[tmp] + 1; bef[p[idxs[tmp][c]][d]] = tmp; if(p[idxs[tmp][c]][d]==akh) sudah = true; else q.push(p[idxs[tmp][c]][d]); } if(sudah) break; } if(sudah) break; } if(dist[akh]==10000000) { printf("-1\n"); return 0; } printf("%d\n",dist[akh]); print(akh); printf("\n"); return 0; } Thanks in advance. Your arrays are too small |
| 32 Mb memory limit. Faint. You can solve it using less than 2 Mb (+) | Dmitry 'Diman_YES' Kovalioff | 1434. Buses in Vasyuki | 26 Jun 2012 17:14 | 3 |
You can also solve it using less than 2 MBs and less than 0.1 seconds :) 32 MB MLE should be even increased because Java and C# coders exist in the world. Nevertheless Timus loves small MLEs for some unknown reasons. But why TLE is 3.0 seconds? 1.0 seconds should be enough. |
| What is wrong? On my computer get the correct result (Pascal) | Timenzzo | 1001. Reverse Root | 26 Jun 2012 13:39 | 2 |
I'm worn out already. Lasarus compiled code. FPC version - 2.6.0. Get the right result. Send in the check, get - Wrong answer (test 3). var c: char; i:longint; l:extended; numbers: array of extended; begin l:=-1; SetLength(numbers,0); while not Eof do begin Read(c); if c in ['0'..'9'] then begin if l=-1 then l:=Ord(c)-48 else l:=l*10+Ord(c)-48; end else begin if l<>-1 then begin SetLength(numbers,length(numbers)+1); numbers[length(numbers)-1]:=sqrt(l); end; l:=-1; end; end; for i:=length(numbers)-1 downto 0 do writeln(numbers[i]:0:4); end. I think couldn't use array to save numbers because size of array not enought to contain. I think on your computer get the correct result because file input data only contain some value, not too much |
| Crash ( access violation ) why ? | diviator | 1001. Reverse Root | 26 Jun 2012 13:09 | 4 |
#include <iostream> #include <fstream> #include <iomanip> #include <cmath> using namespace std; int main() { ifstream f("input.txt"); ofstream o("output.txt"); int n=0; long double a[100]; long double k; f >> k; while(!f.eof()) { a[n] = sqrt(k); n++; f >> k; } for ( int i=n-1 ; i >= 0 ; i-- ) o << fixed << setprecision(4) << a[i] << endl; return 0; } size of array a = 100 is not enought to solve a[i]. size of array maybe more than 1 million double :D I think so Edited by author 25.06.2012 21:43 size of array maybe more than 1 million double :D I think so size of array maybe not more than 131072 values size of array maybe not more than 131072 values So that couldn't use array to save |
| Why?? Memory limit exceeded?? #7 | Thien Diep | 1001. Reverse Root | 25 Jun 2012 21:53 | 1 |
Memory limit exceeded #7 time = 1.312 Memory used = 20 620 KB. Why memory used too much???? :(( #include <iostream> #include <math.h> #include <iomanip> #include <string> #include <sstream> using namespace std; string d2s(double x) { stringstream ii; ii << fixed << setprecision(4) << x; return ii.str(); } int main( ) { double n; string s = ""; while ((cin >> n)) { s = d2s(sqrt(n)) + "\n" + s; } cout << s;
return 0; } |
| crash(access violation) | Dnyaneshwar | 1001. Reverse Root | 25 Jun 2012 21:47 | 2 |
#include<math.h> #include<stdio.h> int main() { double arr[1000]; int i=0,count=0; while(scanf("%lf",&arr[i])) { arr[i] = sqrt(arr[i]); i++; count++; } for(i=count-1;i>=0;i--) printf("\n %0.4lf",arr[i]); return 0; } size of a = 1000 is not enought -> index was out of size size of a maybe more than. Because file size = 256 KB. Unlimit A[i]. So that use array here is difficut to solve this problem! |
| AC at least, but for me this problem very strange! | xurshid_n | 1553. Caves and Tunnels | 25 Jun 2012 17:39 | 1 |
Heavy-Light-Decomposition -> GOOD data structure! thank you all! |
| help,please,why my solution fail? | mythysjh | 1044. Lucky Tickets. Easy! | 25 Jun 2012 16:20 | 4 |
here is my code: #include <stdio.h> int total(int count, int sum) { int result = 0; if( count > 1 ) { int i=0; for (; i <= 9; i++) { result += total(count - 1, sum - i); } } else { return sum < 10 && sum >= 0 ? 1 : 0; } return result; } int main () { unsigned a; int n,i,c,b;
scanf("%ud", &a); b = a / 2 * 9; for(i=0; i <= b; i++ ) { c = total(a/2, i); n += c * c; } printf("%d", n);
return 0; } i tried 2,4,6,8,the result is correct,but when i submit my solution,[wrong answer] is returned... Edited by author 02.09.2011 14:58 i got it,in visual stdio 2010,auto variable must initialized before used Hello Smart :D, Can you please explain how does your algorithm works? I find out that the summation of digits is multiplication of 9 at most; but why (c* c) ???? ( please explain the whole intention behind your algo as well. Thanks Here is the correct code #include <stdio.h> int total(int count, int sum) { int result = 0; if( count > 1 ) { int i=0; for (; i <= 9; i++) { result += total(count - 1, sum - i); } } else { return sum < 10 && sum >= 0 ? 1 : 0; } return result; } int main () { unsigned a; int n = 0; int i,c,b; scanf("%ud", &a); b = a / 2 * 9; for(i=0; i <= b; i++ ) { c = total(a/2, i); n += c * c; } printf("%d", n); return 0; } Here is the correct code |
| I don't understand problem, what "iamb" in example? | xurshid_n | 1866. Poetic Foot | 25 Jun 2012 15:57 | 2 |
In first line trochee, and iamb both has. why no "not a poem" ? Now, I understand, very easy :) Edited by author 15.02.2012 19:38 |
| como puchas se lo resuelve joder1 | ashitaka.advance | 1824. Ifrit Bomber | 25 Jun 2012 03:41 | 1 |
|
| Wrong answer 4! Please help! | Grigorenko Vlad | 1224. Spiral | 24 Jun 2012 13:46 | 1 |
#include<stdio.h> int main(void){ int n,m; unsigned int k; scanf("%d %d",&n,&m); k=0; while(n>2 && m>2){ k=k+4; n-=2; m-=2; } if(n==2 && m>=2) k=k+2; else if(m==2 && n>2) k=k+3; else if(m==1 && n>1) k++; printf("%d",k); return 0; } |
| WA 20 | CapAwsome | 1796. Amusement Park | 24 Jun 2012 00:06 | 1 |
WA 20 CapAwsome 24 Jun 2012 00:06 |
| hint: | xurshid_n | 1503. Polynomial | 23 Jun 2012 19:02 | 1 |
hint: xurshid_n 23 Jun 2012 19:02 |
| To admins: Test data is really, really, really weak | Douglas Cardoso | 1389. Roadworks | 23 Jun 2012 13:47 | 2 |
Please check my submission 4323013. It gets AC although to the input 4 3 1 2 2 4 4 3 it answers 1 2 4 when the right answer is clearly 2 1 2 3 4 Your test was added, 15 authors lost AC. |
| No subject | Giorgi Shavgulidze [Tbilisi SU] [IFG] | 1745. Yet Another Answer | 23 Jun 2012 12:29 | 1 |
No subject Giorgi Shavgulidze [Tbilisi SU] [IFG] 23 Jun 2012 12:29 Edited by author 23.06.2012 12:37 |
| как решать на С++ | saibogo | 1654. Cipher Message | 23 Jun 2012 00:00 | 3 |
Используйте связные списки вместо массивов и не надо будет никаких извращений с предпроверкой считываемых символов. Более того, пройдет даже с использованием cin cout вместо scanf printf. I solved with stack))) time - 0.078 seconds)))) I used only one string. Nothing else. |
| WA#8 | Vitaliy Karelin | 1685. Orthography | 22 Jun 2012 19:20 | 3 |
WA#8 Vitaliy Karelin 28 Feb 2009 17:21 Does anybody has any idea? Me too and I dont think I'm wrong Send your email. I help you. |
| hint on solution | askhatik | 1056. Centers of the Net | 22 Jun 2012 18:46 | 1 |
use DFS with memorization |
| Don't Understand 2nd sample test | Ibragim Atadjanov | 1282. Game Tree | 22 Jun 2012 16:51 | 2 |
I don't understand the 2nd sample test. Is a player go on the path from where the othe player reach? Or are the players move on different path? Each player starts from the point that the other player selects. Here's an explanation for the 2nd test 1 / \ 2 3 / \ / \ 4 5 6 7 - + + 0 If the first player chooses the 2 node, the second player will choose the 4th and win. If the first player chooses the 3 node, the second player will choose the 7th node (he prefers to draw than to loose) So, the player will choose the 3rd node, as he prefers drawing rather than loosing. Edited by author 22.06.2012 16:52 |
| Test | nobik | 1684. Jack's Last Word | 22 Jun 2012 15:46 | 1 |
Test nobik 22 Jun 2012 15:46 abcd aaaaabcdaaaa ans : a a a a abcd a a a a When I print answers,I print them from the end))) Sorry for my poor English)))) Edited by author 22.06.2012 15:47 |