Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Problem with 8 is... | Hanzbrow (TNU) KCC | 1423. String Tale | 3 Mar 2010 21:31 | 4 | Why I've got MLE(19 MB). I use KMP and I don't understand why at all! I appeal to you for help... #include<iostream> #include<string> #include<vector> using namespace std; int main() { int i, j, f=0, n; string what_to_find, gde; cin>>n>>what_to_find>>gde; what_to_find+="#"; what_to_find+=gde; what_to_find+=gde; gde=""; vector<short> next(what_to_find.size()); next[0]=0; for(i=1; i<what_to_find.size(); i++){ if(what_to_find[i]==what_to_find[next[i-1]]) next[i]=next[i-1]+1; else { j = next[i-1]; while (j>0 && what_to_find[i]!=what_to_find[j]){ j=next[j-1]; if(what_to_find[i]==what_to_find[j]) next[i]=j+1; } } if(next[i]==n) { f=1; break; } } if(f) cout<<i-2*n; else cout<<-1; return 0; } When I was using strings,I had MLE 8. Bit in my AC programm I used arrays of char. I get MLE#8 too, using std::string but my AC program with arrays uses only 4.4 MB... Admins, can you please explain such strange behaviour of the judge system? Try to preallocate strings: int n; cin >> n >> ws; string str(n,' '); getline(cin, str); | | Mistake in statement | Fyodor Menshikov | 1417. Space Poker 2 | 3 Mar 2010 19:30 | 3 | подсмотренная ими у каких подвыпивших космонавтов -> подсмотренная ими у каких-то подвыпивших космонавтов | | Java vs MLE | unlucky [Vologda SPU] | 1287. Mars Canals | 3 Mar 2010 19:19 | 2 | If you use Java pay attention to size of arrays, that you used. I used 2 arrays for saving current line and prev line of input(every has o(n) elements), and 2 arrays for saving result of calculating in prev Line, and for saving result of calculation in current line (every has o(n) elements). Edited by author 21.02.2010 15:56 This problem is not so memory consuming. Java solution using variable char field[][] = new char[1 + n + 1][1 + n + 1]; gets AC. So it is possible to store whole input in memory, but it is impossible to store significant amount of data for each cell. For example 4 arrays NxN of 16-bit ints need extra 16 Mb of memory while total ML is 16 Mb. | | Hint: use Java (+) | ASK | 1204. Idempotents | 3 Mar 2010 16:29 | 1 | Make a table of first 3401 primes to factor n; use BigInteger.modInverse instead of coding extended GCD algorithm. | | Output limit exceeded | zam_sabina | | 3 Mar 2010 14:48 | 1 | Who knows what does Output limit exceeded mean? thanks. | | What is the limit for M? | DEF | 1500. Pass Licenses | 2 Mar 2010 13:14 | 5 | It is not actual. Possibly K*N*(N+1)/2. It's also not actual. It seems to me test#20 has multiedges. In that case M is not limited at all )))) | | Help me please... why WA 1? | Winner | 1007. Code Words | 2 Mar 2010 02:05 | 2 | var n: integer; s: string; function Go(s: string): string; var sum: integer; i: integer; j: integer; stmp: string; tmp: integer; begin s:=trim(s); sum:=0; for i:=1 to length(s) do if s[i]='1' then sum:=sum+i;
if (length(s)=n) and (sum mod (n+1) = 0) then begin result:=s; exit; end; if (length(s)=n-1) then begin if sum mod (n+1) = 0 then result:=s+'0' else result:=s+'1'; exit; end; if (length(s)=n+1) then begin for i:=1 to length(s) do begin stmp:=s; Delete(stmp,i,1); tmp:=0; for j:=1 to length(stmp) do if stmp[j]='1' then tmp:=tmp+j; if tmp mod (n+1) = 0 then begin result:=stmp; exit; end; end; end; for i:=length(s) downto 1 do if (s[i]='1') then if ((sum-i) mod (n+1) = 0) then begin s[i]:='0'; break; end else else if ((sum+i) mod (n+1) = 0) then begin s[i]:='1'; break; end; result:=s; end; begin // assign(input,'input.txt'); reset(input); readln(n); while not eof do begin readln(s); writeln(Go(s)); end; // sleep(12121); end. see also this (or give more test data): #include <iostream> #include <string> using namespace std; short N; char word[2001][1001]; int main(){ int i=0,j,n,s=0,c=0,temp; cin>>N; while(cin>>word[i])i++; n=i; for(i=0;i<n;i++){ ////////////////////// CASE 1 (REPLACED)////////////////////// if(strlen(word[i])==N){ for(j=0;j<N;j++) if(word[i][j]=='1')s+=j+1; s%=(N+1); word[i][s-1]='0'; } ////////////////////// CASE 2 (REMOVED)////////////////////// else if(strlen(word[i])==N-1){ for(j=0;j<N-1;j++) if(word[i][j]=='1'){ s+=j+1; c++; } s%=(N+1); if(s!=0)s=N+1-s; if(s<=c){ // Removed '0' for(j=N-2;s!=0;j--){ word[i][j+1]=word[i][j]; if(word[i][j]=='1')s--; } word[i][j+1]='0'; } else { // Removed '1' short mod=s; c=0; for(j=s;j<N-1;j++) if(word[i][j]=='1')c++; while(s+c!=mod){ s--; if(word[i][s-1]=='1')c++; } for(j=N-1;j>=s;j--)word[i][j]=word[i][j-1]; word[i][s-1]='1'; } } ////////////////////// CASE 3 (INSERTED)////////////////////// else if(strlen(word[i])==N+1){ for(j=0;j<N+1;j++) if(word[i][j]=='1')s+=(j+1); s%=(N+1); for(j=N;j>=0 && c!=s;j--) if(word[i][j]=='1')c++; if(j>=0 && word[i][j]=='0'){ // Inserted '0' for(;j<N;j++)word[i][j]=word[i][j+1]; word[i][j]=0; } else { // Inserted '1' if(s==0)s=N+1; short mod=s; c=0; for(j=s;j<N+1;j++) if(word[i][j]=='1')c++; while(s+c!=mod){ s--; if(word[i][s]=='1')c++; } for(j=s-1;j<N+1;j++)word[i][j]=word[i][j+1]; word[i][j]=0; } } s=c=0; } for(i=0;i<n;i++)cout<<word[i]<<endl; return 0; } | | Codeforces Beta Round #3 - http://codeforces.com/ | MikeMirzayanov | | 1 Mar 2010 16:02 | 1 | Welcome to the next http://codeforces.com/ round. I'm glad to invite you to take part in Codeforces Beta Round #3. It starts on Thursday, March 4, 2010 19:30 (UTC +3, Moscow time). Click http://www.timeanddate.com/worldclock/fixedtime.html?year=2010&month=03&day=04&hour=16&min=30&sec=0&p1=0to view the time in the other time zones. The contest duration is 2 hours. The allowed programming languages are C/C++, Pascal, Java, C#, Python, Ruby and PHP. Recently we have introduced Codeforces rating system. Currently vepifanov is the highest-rated coder, but Codeforces is at the initial stage now, and all sorts of changes can be introduced in future. Want to compete? - click http://codeforces.com/contests/ If you are Russian speaking try http://codeforces.ru/. Wish you high rating, MikeMirzayanov --- http://codeforces.com/http://codeforces.ru/ | | How is this posible? | cNoNim | 1001. Reverse Root | 28 Feb 2010 20:17 | 3 | execution time depends on at what time starts the test? ie of server load? Try to use the array of chars:) | | TLE, what's wrong | Rudnev Vladimir | 1021. Sacrament of the Sum | 28 Feb 2010 16:33 | 2 | var b,a:array[1..50000]of int64; n,m,i,j:longint; begin readln(n); for i:=1 to n do readln(a[i]); readln(m); for j:=1 to m do readln(b[j]); for i:=1 to n do for j:=1 to m do if a[i]+b[j]=10000 then begin writeln('YES'); halt(0);end; writeln('NO'); end. n<=50000? m<=50000, 50000*50000=2 500 000 000, so in simple computer it is 2500 seconds, it is too long, isn't it?)) | | WA#1 | frp | 1037. Memory Management | 26 Feb 2010 21:27 | 1 | WA#1 frp 26 Feb 2010 21:27 I got WA#1. But my program gives correct result for all tests what i found on this forum. Why WA#1? Please give tests where my program will give incorrect result. My source code: //////////////////////////// ///Stupid brute force #include <iostream> #include <cstdio> using namespace std; int mem[30000]; //set<int> fb; int main() { char a[100]; char c; int ltd=0; int i; for(i=0;i<30000;i++)mem[i]=0; while(!cin.eof()) { cin.getline(a,100); int t,mp; sscanf(a,"%d %c%d",&t,&c,&mp); mp--; int mfb=40000; for(i=0;i<30000;i++) { mem[i]-=t-ltd; if((mem[i]<1)&&(i<mfb)){mfb=i;if(t==ltd)break;} } if(c=='+') { mem[mfb]=600; cout<<mfb+1<<'\n'; } else { if(mem[mp]>0){mem[mp]=600;cout<<"+\n";} else cout<<"-\n"; } ltd=t; } return 0; } | | what's wrong | dheman | 1493. One Step from Happiness | 26 Feb 2010 02:47 | 2 | my code is #include<stdio.h> #include<string.h> int main() { char a[10]; while(scanf("%s",a)==1) { long int s1=0,s2=0; long int len = strlen(a); for(long int i=0;i<len;i++) { if(i<3) s1 = s1 + (a[i]-'0'); else s2 = s2 + (a[i] - '0'); } long int sub = s1 - s2;
if(sub ==1 || sub== -1) { if(sub==1) { long int add = (a[len-1]-'0')+1; if(add>9) { printf("No\n"); } else printf("Yes\n"); } else if(sub == -1) { if(a[len-1]<1) printf("No\n"); else printf("Yes\n"); } } else printf("No\n"); } return 0; } i don't know where is my problem. please help me. opps. sorry .. i found my mistake.. | | WA on test #2 | frp | 1008. Image Encoding | 25 Feb 2010 22:57 | 1 | Why I have wa #2? My solution: /////////////// #include <iostream> #include <cstdio> #include <queue> #include <map> using namespace std; #define mkpair make_pair int main() { int n,m; char a[300]; cin.getline(a,300); int fmt=sscanf(a,"%d%d",&n,&m); bool fmt1; bool pic[10][10]; bool pic2[10][10]; int ml[10],md[10]; if(fmt==1)fmt1=true;else fmt1=false; if(fmt1) { int i,j,x,y; for(i=0;i<10;i++) for(j=0;j<10;j++){pic[i][j]=false;pic2[i][j]=false;} for(i=0;i<10;i++){ml[i]=100;md[i]=100;} for(i=0;i<n;i++) { cin>>x>>y; x--;y--; pic[y][x]=true; if(ml[y]>x)ml[y]=x; if(md[x]>y)md[x]=y; } int mdl=100,mdd=-1; for(i=0;i<10;i++) { if(ml[i]<mdl)mdl=ml[i]; } mdd=md[mdl]; cout<<mdl+1<<" "<<mdd+1<<"\n"; queue<pair<int,int> > pc; pc.push(mkpair(mdl,mdd)); while(!pc.empty()) { x=pc.front().first;y=pc.front().second;pc.pop(); pic2[y][x]=true; if(x<9 && !pic2[y][x+1] && pic[y][x+1]){cout<<"R";pic2[y][x+1]=true;pc.push(mkpair(x+1,y));} if(y<9 && !pic2[y+1][x] && pic[y+1][x]){cout<<"T";pic2[y+1][x]=true;pc.push(mkpair(x,y+1));} if(x>0 && !pic2[y][x-1] && pic[y][x-1]){cout<<"L";pic2[y][x-1]=true;pc.push(mkpair(x-1,y));} if(y>0 && !pic2[y-1][x] && pic[y-1][x]){cout<<"B";pic2[y-1][x]=true;pc.push(mkpair(x,y-1));} if(pc.empty())cout<<".\n";else cout<<",\n"; } } else { queue<pair<int,int> > pc; pc.push(mkpair(n-1,m-1)); int i,j; for(i=0;i<10;i++) for(j=0;j<10;j++){pic[i][j]=false;pic2[i][j]=false;} int cnt=0; bool dr=true; while(!pc.empty()) { cnt++; int y=pc.front().second,x=pc.front().first;pc.pop(); pic[y][x]=true; char c='\0'; while((c!=',')&&(c!='.')&&(dr)) { cin>>c; switch(c) { case 'R':pic[y][x+1]=true; pc.push(mkpair(y,x+1)); break; case 'T':pic[y+1][x]=true; pc.push(mkpair(y+1,x)); break; case 'L':pic[y][x-1]=true; pc.push(mkpair(y,x-1)); break; case 'B':pic[y-1][x]=true; pc.push(mkpair(y-1,x)); break; } dr=(c!='.'); } } int y,x; cout<<cnt<<'\n'; for(x=0;x<10;x++) for(y=0;y<10;y++) if(pic[y][x])cout<<x+1<<' '<<y+1<<'\n'; } return 0; } ////////////////////////// | | C compiler does not follow C99 Standard | Tony Beta Lambda | 1010. Discrete Function | 25 Feb 2010 12:24 | 3 | C99 7.20.6.1: long long int llabs(long long int j); but when I submit my code with use of llabs, I got CE. fmax(double,double) also doesn't work well LLONG_MAX will get CE too. | | WA2,……help me | MeLodyloveyr | 1750. Pakhom and the Gully | 25 Feb 2010 12:19 | 1 | I use shortest path to solve this problem... | | Why WA 8? | 李春骐 | 1016. Cube on the Walk | 25 Feb 2010 10:51 | 2 | I used SPFA, but failed in test 8. Who can help me? #include <stdio.h> #include <string.h> #define INF 0x3f3f3f3f int op[] = {0, 2, 1, 5, 6, 3, 4}; int r[7][7] = { {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 4, 5, 6, 3}, {0, 0, 0, 6, 3, 4, 5}, {0, 6, 4, 0, 1, 0, 2}, {0, 3, 5, 2, 0, 1, 0}, {0, 4, 6, 0, 2, 0, 1}, {0, 5, 3, 1, 0, 2, 0} }; struct State { int x, y, b, f; //表示坐标(x, y)和底面和前面上的标号 } beg, end, que[24*8*8*100]; bool inque[9][9][7][7]; int dist[9][9][7][7], a[7], path[24*8*8*2]; int ans = 1000000000, last; char s1[4], s2[4]; void eval(State &s, int x, int y, int b, int f) { s.x = x, s.y = y, s.b = b, s.f = f; } bool check(State &s) { if (s.x == 0 || s.x > 8 || s.y == 0 || s.y > 8) return 0; return 1; } void SPFA() { int closed = 0, open = 2; memset(dist, 0x3f, sizeof(dist)); eval(que[1], beg.x, beg.y, beg.b, beg.f); inque[beg.x][beg.y][beg.b][beg.f] = 1; dist[beg.x][beg.y][beg.b][beg.f] = 0; do { closed++; inque[que[closed].x][que[closed].y][que[closed].b][que[closed].f] = 0; if (que[closed].x == end.x && que[closed].y == end.y && dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] < ans) { ans = dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f]; last = closed; } State newst; // forward eval(newst, que[closed].x, que[closed].y-1, que[closed].f, op[que[closed].b]); if (check(newst)) { if (dist[newst.x][newst.y][newst.b][newst.f] > dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] + a[newst.b]) { dist[newst.x][newst.y][newst.b][newst.f] = dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] + a[newst.b]; if (!inque[newst.x][newst.y][newst.b][newst.f]) { inque[newst.x][newst.y][newst.b][newst.f] = 1; que[open] = newst; path[open] = closed; open++; } } } // right eval(newst, que[closed].x+1, que[closed].y, r[que[closed].b][que[closed].f], que[closed].f); if (check(newst)) { if (dist[newst.x][newst.y][newst.b][newst.f] > dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] + a[newst.b]) { dist[newst.x][newst.y][newst.b][newst.f] = dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] + a[newst.b]; if (!inque[newst.x][newst.y][newst.b][newst.f]) { inque[newst.x][newst.y][newst.b][newst.f] = 1; que[open] = newst; path[open] = closed; open++; } } } // backward eval(newst, que[closed].x, que[closed].y+1, op[que[closed].f], que[closed].b); if (check(newst)) { if (dist[newst.x][newst.y][newst.b][newst.f] > dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] + a[newst.b]) { dist[newst.x][newst.y][newst.b][newst.f] = dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] + a[newst.b]; if (!inque[newst.x][newst.y][newst.b][newst.f]) { inque[newst.x][newst.y][newst.b][newst.f] = 1; que[open] = newst; path[open] = closed; open++; } } } // left eval(newst, que[closed].x-1, que[closed].y, op[r[que[closed].b][que[closed].f]], que[closed].f); if (check(newst)) { if (dist[newst.x][newst.y][newst.b][newst.f] > dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] + a[newst.b]) { dist[newst.x][newst.y][newst.b][newst.f] = dist[que[closed].x][que[closed].y][que[closed].b][que[closed].f] + a[newst.b]; if (!inque[newst.x][newst.y][newst.b][newst.f]) { inque[newst.x][newst.y][newst.b][newst.f] = 1; que[open] = newst; path[open] = closed; open++; } } } } while (closed < open); } void print(int i) { if (que[i].x == beg.x && que[i].y == beg.y) { printf("%d %c%d", ans+a[beg.b], beg.x+'a'-1, beg.y); return; } print(path[i]); printf(" %c%d", que[i].x+'a'-1, que[i].y); } int main() { scanf("%s%s%d%d%d%d%d%d", s1, s2, &a[1], &a[2], &a[3], &a[4], &a[5], &a[6]); beg.x = s1[0] - 'a' + 1; beg.y = s1[1] - '0'; beg.b = 5; beg.f = 1; end.x = s2[0] - 'a' + 1; end.y = s2[1] - '0'; SPFA(); print(last); printf("\n"); return 0; } | | Place more samples!!!(-) | Sergey Lazarev (MSU Tashkent) | 1524. Men in Black | 24 Feb 2010 21:04 | 6 | Aga. Another more sophisticated sample would be very helpful! It seems that all tests including Test 4 are correct. But still WA4... What the f... I missed? To nikonoff. Sergey Lazarev (MSU Tashkent) 21 Feb 2010 20:53 I suggest to exchange our tests and compare answers to find mistakes. Agreed Edited by author 24.02.2010 14:03 | | timus_support@acm.timus.ru does not work | Fyodor Menshikov | | 24 Feb 2010 18:51 | 2 | I got the following answer when tried to send test to Timus team: ----- The following addresses had permanent fatal errors ----- judge_mailbox@busin.usu.ru (reason: 550 5.1.1 User unknown) (expanded from: <timus_support@acm.timus.ru>) ----- Transcript of session follows ----- 550 5.1.1 judge_mailbox@busin.usu.ru... User unknown I have received your message. But one of the other recipients had a problem with his mailbox. This mailbox is fixed now. | | WA 7 | Marginean Ciprian | 1587. Flying Pig | 23 Feb 2010 20:40 | 1 | WA 7 Marginean Ciprian 23 Feb 2010 20:40 Maybe someone could give me some tests to find the bug in my program. I have tried the tests on this forum(and others) and it provides the correct answer(for those tests). L.E.: Never mind, I got accepted. Using an automated test generator, which I wrote, I found that my program failed to provide a correct answer on the following test: //Input 2 -1 -1 //Correct Output 1 //My Output -1 And obviously, it failed all tests of the type n -1 -1 ... -1 by providing the answer -1. Maybe this will help others of wasting a few days on the problem. Edited by author 23.02.2010 21:27 | | Why i got crash??? | Rudnev Vladimir | 1585. Penguins | 23 Feb 2010 00:32 | 4 | what's wrong??? var a:array[1..1000] of string;v,b,c,n,i:integer; begin b:=0;c:=0;v:=0; read(n); for i:=1 to n+1 do begin readln(a[i]); if a[i]='Emperor Penguin' then v:=v+1; if a[i]='Macaroni Penguin' then b:=b+1; if a[i]='Little Penguin' then c:=c+1; end; if (v>b)and(v>c)then writeln('Emperor Penguin'); if (b>v)and(b>c)then writeln('Macaroni Penguin'); if (c>b)and(c>v)then writeln('Little Penguin'); end. Why "for i:=1 to n+1 do"??? Must be "for i:=1 to n do"!!! if i do "for i:=1 to n do" then (не знаю как дальше поанглийски) Короче он вводит на 1 меньше Change "read(n)" to "readln(n)". |
|
|