Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | Страница 4 | weak tests | tereshinvs | 1220. Stacks | 8 авг 2010 03:00 | 1 | i've got a data:array[0..80000] of longint for save numbers and got AC! why there aren't tests like 100000 operators: 100000 PUSH 1 1 PUSH 1 2 ... PUSH 1 100000 ? funny: data:array[0..100000] gives MLE 1 data:array[0..50000] gives WA 16 data:array[0..90000] gives WA 10 data:array[0..80000] gives AC... | I get AC with 2 paths | Platto Pavel | 1220. Stacks | 13 янв 2011 11:35 | 2 | First, very stupied method: used just 2 arrays for A and B values, 0.609s, 673KB. Second, some hint: used multi-stack and for pointers at next element used unsigned short, 0.031s, 677KB. Sorry, for bad english:-) I used 2 arrays for A and B values and O(n) algorithm | Unbelievable,, MLE #10 or WA #3 | Zhihua Lai | 1220. Stacks | 29 мар 2010 20:03 | 2 | Edited by author 05.04.2010 05:23 Edited by author 05.04.2010 05:24 | MLE 10 Why? | Zhihua Lai | 1220. Stacks | 29 мар 2010 18:40 | 2 | Edited by author 05.04.2010 05:24 Edited by author 05.04.2010 05:24 | ML10 - 0.9mb | Rayzor | 1220. Stacks | 18 ноя 2009 02:33 | 2 | I tryed to minimize using of memory, but... #include <cstdio> #include <stack> #include <map> using namespace std; map<unsigned int,stack<unsigned int> > m; unsigned int n, i, b; unsigned short a; char c; void main(void) { scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s%s",c,c);
if (c == 'U'){ scanf("%d %d\n",&a,&b); m[a].push(b); }else{ scanf("%d\n",&a); printf("%d\n",m[a].top()); m[a].pop(); } } } Hi, Don't use Maps and Stacks. They take too much memory. You need to try to solve this problem by just including <cstdio> library and nothing else. However, I still can't do it even though I am doing that and using dynamic arrays. I am getting MLE 12. Varun | use same memory in all test but MLE test 10, WHY? | Alexander J. Villalba G. | 1220. Stacks | 14 сен 2009 19:48 | 3 | OK Denis Koshman, I did (thanks) but MLE test 10 why? the program in all test use same memory and no use dinamic memory BUT MLE test 10 WHY? is unbelive !!! #include <iostream> #include <string> using namespace std; unsigned int a[100000]; unsigned short b[100000]; int f[1000]; int nn=0; inline int get_value(unsigned x) { return a[x] & 0x7FFFFFFF; } inline void set_value(unsigned x, unsigned v) { (a[x] &= 0x80000000) |= v; } inline int get_next(unsigned x) { return b[x] | ((a[x]>>31)<<16); } inline int set_next(unsigned x, unsigned v) { b[x] = v, (a[x] &= 0x7FFFFFFF) |= (v>>16)<<31; } void push (int pila, int v) { int x = nn++; // 'nn' is global ever-growing variable set_value(x, v); set_next(x, f[pila]); f[pila] = x; } void pop(int pila) { cout << get_value(f[pila]) << endl; f[pila] = get_next(f[pila]); } int main (void) { int n; int pila, v; cin >> n; string s; unsigned int a,b,ss=0; for(int i=0; i<n; i++) { cin >> s; if(s=="PUSH") { cin >> pila; cin >> v; push(pila, v); } if(s=="POP") { cin >> pila; pop (pila); } } return 0; } 1. remove #include <iostream> #include <string> using namespace std; ...cin... ...cout... 2. but use #include <cstdio> ...scanf ()... ...printf ()... 3. You'll get AC because <iostream> use some extra memory more than <stdio.h> 4. about MLE Timus Judge counts only real used memory for current test while executable running. e.g. static int vector [4*1024*1024]; ... for (int i = 0; i < 1024*1024; ++i) { ...vector [i]... } this code gives you only 4MB used (not 16MB as expected) this fact checked experimentally... | Anybody knows about MLE#10 | gt11 | 1220. Stacks | 23 июн 2009 03:12 | 2 | What's so cool in this test? It pushes a lot into one stack or a lot into many stacks or what? #include <iostream> using namespace std; struct elem { unsigned int value; elem * next; }; elem ** tree; elem * push(elem * stack,unsigned int value) { if(!stack) { stack = new elem; stack->value = value; stack->next = NULL; return stack; } else { elem * temp = new elem; temp->value = value; temp->next = stack; return temp; } } elem * pop(elem * stack,unsigned int & value) { elem * temp = stack->next; value = stack->value; delete stack; return temp; } int main() { tree = new elem* [1000]; memset(tree,0,1000*4); int n; cin>>n; char str[5]; int a; unsigned int b; for(int i = 0;i<n;++i) { cin>>str; if(str[1]=='U') { cin>>a; cin>>b; tree[a-1] = push(tree[a-1],b); } else { cin>>a; unsigned int value; tree[a-1] = pop(tree[a-1],value); cout<<value<<endl;
} }
return 0; } OMG. Changed iostream on stdio.h and it got accepted!! :) 713kb OMG OMG OMG | 10 WA, what's wrong with my code? | Mgccl | 1220. Stacks | 14 апр 2009 23:07 | 2 | int main(int argc, char **argv){ char s[6]; int n,i,t; unsigned int a[100001]; unsigned short b[100001]; unsigned int f[1001]; unsigned int d; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%s", s); if(s[1]=='U'){ scanf("%d %u", &t, &d); a[i]=d<<1; b[i]=f[t]>>1; a[i]+=f[t]&1; f[t]=i; }else{ scanf("%d",&t); printf("%u\n",a[f[t]]>>1); f[t] = (((int)b[f[t]])<<1)+(a[f[t]]&1); } } return 0; } You should set f[0] - f[1001] = 0 | Need help!!! | Lebedev_Nicolay[Ivanovo SPU] | 1220. Stacks | 29 мар 2009 15:50 | 2 | I had MLE #1 with 2 arrays: (C ++) int a[ 100000 ], short b[ 100000 ]; How to use 1 array instead of two??? int a[ 100000 ], short b[ 1000 ]; | MLE #1 | Lebedev_Nicolay[Ivanovo SPU] | 1220. Stacks | 28 мар 2009 23:31 | 8 | MLE #1 Lebedev_Nicolay[Ivanovo SPU] 1 мар 2009 16:10 I use : int a[ 100000 ]; short num[ 100000 ]; And I have MLE #1!!! 100000 * 4 + 100000 * 2 = 600000 bytes + plus memory for your programm. Memory limit can be 750000 bytes instead of 750 Kb. Re: MLE #1 Lebedev_Nicolay[Ivanovo SPU] 1 мар 2009 21:37 Re: MLE #1 Vedernikoff Sergey (HSE: EconomicsForever!) 1 мар 2009 21:44 You use too much memory. Try to fit into one array int[100000]... Re: MLE #1 Lebedev_Nicolay[Ivanovo SPU] 1 мар 2009 23:12 Can you prompt me? I can't think up how to do it. Re: MLE #1 Vedernikoff Sergey (HSE: EconomicsForever!) 2 мар 2009 03:15 For example, look at corresponding section in D. Knuth's book (something about several stacks in one memory segment) Re: MLE #1 Lebedev_Nicolay[Ivanovo SPU] 4 мар 2009 23:18 I can't find it!? Can you tell me any idea??? Re: MLE #1 Amirbekov Artem[Ivanovo SPU] 28 мар 2009 23:31 Just use the "realloc()" function ;-) | Tests are not stronger??? | Programmer | 1220. Stacks | 4 фев 2009 14:27 | 1 | My programm have MLE10, but when I add dispose after each POP operation it is AC. Why? I think it don`t have to be like this in this problem. | Java solution exists! | Fyodor Menshikov | 1220. Stacks | 30 мар 2009 08:49 | 4 | I've solved this problem in Java! http://acm.timus.ru/status.aspx?space=1&num=1220&author=23793 FAQ ( http://acm.timus.ru/help.aspx?topic=java&locale=en) says "Here is the list of the problems which are not guaranteed to be solvable in Java: 1220, 1275, 1306." Now 1220 may be removed from this list. Russian version of the FAQ slightly more close to the truth. It says that problems except 1220, 1275 and 1306 may be solved in Java _without_significant_difficulties_. And this statement is true. 1220 _may_ be solved in Java, but with much more difficulty than in Pascal or C++. how to C# ? Your solution 2525637 uses only 300 kb of memory. Probably it does nothing, but 750-300 kb is enough to get AC using right techniques. The most important is to not create objects. So no strings, only reusable arrays of characters. And probably you are to implement reading and writing classes over byte IO that do not use object creation. Your solution 2525637 uses only 300 kb of memory. Probably it does nothing. ------------------------ Yes, it's only: static void Main(){} but it uses 365KB memory. The most important is to not create objects. So no strings, only reusable arrays of characters. And probably you are to implement reading and writing classes over byte IO that do not use object creation. ------------------- i shall try. thank you very much. | Crash(acsses violation) on 3test | [USU]And_IV[КБ-101] | 1220. Stacks | 9 фев 2014 22:41 | 2 | why??? #include <iostream> //#include <stdlib.h> //#include <stdio.h> #include <string.h> using namespace std; int i,o,tp,nm; struct Tpart { int val [24]; int k; Tpart *lst;
}; char com[100]; Tpart stk[1024]; int Pop(Tpart *p) { if(p->k>0) return p->val[--(p->k)]; else { Tpart *e=p; p=p->lst; delete e; return p->val[--(p->k)]; }}; void Push(Tpart *p, int val) { if((p->k)<24) (p->val)[(p->k)++]=val; else { Tpart *uk= new Tpart; uk->lst=p; p=uk; p->k=0; (p->val)[(p->k)++]=val; } return; } int main() { int n; cin>>n; for(int j=0;j<n;j++) { cin>>com; if (strcmp(com,"PUSH")==0) { cin>>nm>>tp; Push(&stk[nm-1],tp); } if (strcmp(com,"POP")==0) { cin>>nm; cout<<Pop(&stk[nm-1])<<endl;} } return 0; } | What's wrong with my program?? WA at 10# | boats | 1220. Stacks | 17 фев 2009 01:07 | 2 | program t1220; var i,k,m,n:longint; st:array[1..1000] of longint; a:array[0..100000] of longint; f:array[0..100000] of word; s:char; begin readln(n); for i:=1 to n do begin read(s,s,s,s); if s='H' then begin readln(k,a[i]); f[i]:=st[k]; st[k]:=i; end else begin readln(k); writeln(a[st[k]]); st[k]:=f[st[k]]; end; end; end. I think this is wrong in this program: f:array[0..100000] of word; WORD type too small, but array[0..100000] of longword is too large... I've used this strange array: morethen50k:array[0..100000] of byte; ;) Edited by author 17.02.2009 01:08 Edited by author 17.02.2009 01:08 | why i have got Memory limit exceeded ? | Canhtoan | 1220. Stacks | 29 окт 2008 21:10 | 6 | I have got this in test 10 ,can anyone tell me ? i only use an array 1..1000 of pointer ? but my program :898 kb in test 10 ? Const Fi =''; Go =''; Limit =1001; Type pt =^pts; Pts=record Data:Longint; Link:Pt; end; Var f,g :text; N :Longint; St :array[1..Limit] of pt; Procedure OpenFile; Begin Assign(f,fi); Reset(f); Assign(g,go); Rewrite(g); End; Procedure CloseFile; begin Close(f); Close(g); End; Procedure Push(i,j:Longint); var p:pts; Begin New(p); p^.data:=i; p^.link:=St[j]; ST[j]:=p; End; Function Pop(j:Integer):Longint; Var p :Pt; Begin Pop := St[j]^.data; P := St[j]^.link; Dispose(St[j]); St[j] :=P; End; Procedure Solve; Var i,a,b:Longint; s:string; Ch:char; Begin For i:=1 to 1000 do St[i]:=Nil; Readln(f,n); For i:=1 to n do BEgin S:=''; While True do BEgin Read(f,ch); if ch=' ' then Break; S:=S+ch; End; if S='PUSH' Then Begin Readln(f,a,b); Push(B,a); End Else Begin Readln(f,a); Writeln(g,Pop(a)); End; End; End; Begin OpenFile; Solve; CloseFile; End. Edited by author 29.10.2008 09:53 Try this test : N = 100000 PUSH 1 100 PUSH 1 100 ... PUSH 1 100 ( there are only "PUSH"s ) In this case, your memory will be 100000 * sizeof( pts ) ~ 800KB ( > 0.75 MB ). That doesn't include the memory for running your program. Const Fi =''; Go =''; Limit =100001; Var f,g :text; N :Longint; Labels :array[1..Limit] of Integer; A :array[1..Limit] of Longint; Procedure OpenFile; Begin Assign(f,fi); Reset(f); Assign(g,go); Rewrite(g); End; Procedure CloseFile; begin Close(f); Close(g); End; Procedure Solve; Var i,j,last,x:Longint; s:string[5]; Ch:char; Begin Readln(f,n); Last:=0; For i:=1 to n do BEgin S:=''; While True do BEgin Read(f,ch); if ch=' ' then Break; S:=S+ch; End; if S='PUSH' Then Begin Inc(last); Readln(f,Labels[Last],A[Last]); End Else Begin Readln(f,X); For j:=last downto 1 do if Labels[j]=x then Begin Labels[j]:=0; Writeln(g,A[j]); Break; End; End; End; End; Begin OpenFile; Solve; CloseFile; End. Edited by author 29.10.2008 10:15 in vietnamese : anh Hiếu :lần này em chỉ sử dụng 2 mảng 1..100000 of longint và integer ,như vậy mem chỉ mất 0,6 mb nhưng nó vẫn bị MLE :( , ở test 10 :( Const Fi =''; Go =''; Limit =100001; Var f,g :text; N :Longint; Labels :array[1..Limit] of Integer; A :array[1..Limit] of Longint; Procedure OpenFile; Begin Assign(f,fi); Reset(f); Assign(g,go); Rewrite(g); End; Procedure CloseFile; begin Close(f); Close(g); End; Procedure Solve; Var i,j,last,x:Longint; s:string[5]; Ch:char; Begin Readln(f,n); Last:=0; For i:=1 to n do BEgin S:=''; While True do BEgin Read(f,ch); if ch=' ' then Break; S:=S+ch; End; if S='PUSH' Then Begin Inc(last); Readln(f,Labels[Last],A[Last]); End Else Begin Readln(f,X); For j:=last downto 1 do if Labels[j]=x then Begin Labels[j]:=0; Writeln(g,A[j]); Break; End; End; End; End; Begin OpenFile; Solve; CloseFile; End. Edited by author 29.10.2008 10:14 Edited by author 29.10.2008 10:14Because on Timus, integer = longint (Pascal) = 4 bytes. You should use Word or SmallInt (2 bytes) for array "Labels". Good luck thanks to mr.N.M.Hieu ( DHSP ) :) | how to solve this F!@#$%G problem? | Experimenter | 1220. Stacks | 14 сен 2009 18:46 | 12 | MLE#10 #include <iostream> #include <string> using namespace std; struct aaa { unsigned int a :30; }pop[1001],data[100001][2]; int main() { int n; cin >> n; string s; unsigned int a,b,ss=0; for(int i=0; i<n; i++) { cin >> s; if(s=="PUSH") { cin >> a >> b; data[ss][0].a=b; data[ss][1].a=pop[a].a; pop[a].a=ss; ss++; } if(s=="POP") { cin >> a; cout << data[pop[a].a][0].a << endl; data[pop[a].a][0].a=0; pop[a].a=data[pop[a].a][1].a; } } } Edited by author 26.08.2008 15:33 i rewrote it without using strings and "namespace std" but MLE10 again( may be it is unreal problem? i think it can't be solved without array for 10^5 elements.... wrong cheker? I keep two big arrays: dword a[100000] word nx[100000] int f[1000] bits 0..30 of 'a' - value bits 0..15 of 'nx' together with 31th bit of 'a' - index of next item in the same stack 'f' - index of the top for corresponding stack >together with 31th bit of 'a' how can i write it? i have ML(( #include <iostream.h> struct aaa { unsigned a :30; unsigned n :14; }data[100001]; struct bbb { unsigned a :14; }pop[1001]; int main() { int n; cin >> n; char c; unsigned int a,b,ss=0; for(int i=0; i<n; i++) { cin >> c; cin >> c; if(c=='U') { cin >> c; cin >> c; cin >> a >> b; data[ss].a=b; data[ss].n=pop[a].a; pop[a].a=ss; ss++; }else { cin >> c; cin >> a; cout << data[pop[a].a].a << endl; data[pop[a].a].a=0; pop[a].a=data[pop[a].a].n; } } return 0; } unsigned int a[100000]; unsigned short b[100000]; inline int get_value(unsigned x) { return a[x] & 0x7FFFFFFF; } inline void set_value(unsigned x, unsigned v) { (a[x] &= 0x80000000) |= v; } inline int get_next(unsigned x) { return b[x] | ((a[x]>>31)<<16); } inline int set_next(unsigned x, unsigned v) { b[x] = v, (a[x] &= 0x7FFFFFFF) |= (v>>16)<<31; } When you push item 'v' to stack 'i', you perform: int x = nn++; // 'nn' is global ever-growing variable set_value(x, v) set_next(x, f[i]); f[i] = x; when you pop item from stasck 'i', you perform: cout << get_value(f[i]); f[i] = get_next(f[i]); Another approach does not use bit manipulationson, but relies on fact that every output value requires two commands in the input (push and pop). i just use dynamic arrays and nothing more :) int* a[1001]; int len[1001]; void add(int ind,int data) { len[ind]++; a[ind]=(int*)realloc(a[ind],len[ind]*4); a[ind][len[ind]-1]=data; } int del(int ind) { --len[ind]; int res=a[ind][len[ind]]; a[ind]=(int*)realloc(a[ind],len[ind]*4); return res; } it accepts with large time but with extra small memory Strange, Oracle, that shouldn't work on hard test cases. Not only because of time, but because of memory too. I've used short s[100000], long a[100000], long top[1000]. Time - 0.234 Memory - 721 KB Edited by author 25.01.2009 03:19 Edited by author 25.01.2009 03:19 ID 2260315 Oracle[Lviv NU] 1220 C++ Accepted 0.765 529 KB OK Denis Koshman, I did (thanks) but MLE test 10 why? the program in all test use same memory and no use dinamic memory BUT MLE test WHY? is unbelive !!! #include <iostream> #include <string> using namespace std; unsigned int a[100000]; unsigned short b[100000]; int f[1000]; int nn=0; inline int get_value(unsigned x) { return a[x] & 0x7FFFFFFF; } inline void set_value(unsigned x, unsigned v) { (a[x] &= 0x80000000) |= v; } inline int get_next(unsigned x) { return b[x] | ((a[x]>>31)<<16); } inline int set_next(unsigned x, unsigned v) { b[x] = v, (a[x] &= 0x7FFFFFFF) |= (v>>16)<<31; } void push (int pila, int v) {
int x = nn++; // 'nn' is global ever-growing variable set_value(x, v); set_next(x, f[pila]); f[pila] = x; } void pop(int pila) { cout << get_value(f[pila]) << endl; f[pila] = get_next(f[pila]); } int main (void) { int n; int pila, v; cin >> n; string s; unsigned int a,b,ss=0;
for(int i=0; i<n; i++) { cin >> s; if(s=="PUSH") { cin >> pila; cin >> v; push(pila, v); }
if(s=="POP") {
cin >> pila; pop (pila); } } return 0; } Edited by author 14.09.2009 18:47 I read input several times and get AC in C++. | Good strong test cases | ata_tnu | 1220. Stacks | 28 июн 2008 00:17 | 1 | Please someone give me hard test cases because my prog gets WA at 8 test. Dear authors, what is 8th test? | why WA1 ?? | Anupam Ghosh,Bengal Engg and Sc Uni,MtechIT,2006-09,India | 1220. Stacks | 22 апр 2008 11:57 | 1 | why WA1 ?? Anupam Ghosh,Bengal Engg and Sc Uni,MtechIT,2006-09,India 22 апр 2008 11:57 can somebody please suggest some test cases. | Please help.MLE#10.Thank! | CHIDEMYAN SERGEY | 1220. Stacks | 10 ноя 2007 22:38 | 1 | #include<iostream> using namespace std; #include<stack> #include<vector> int main() { std::stack<int,std::vector<int> >val[1001]; int k,i=0,n,m; cin>>k; char a[4]; while(i<k) { cin>>a; if(a[1]=='U') { cin>>n>>m; val[n].push(m); } else if(a[1]=='O') { cin>>n; cout<<val[n].top()<<endl; val[n].pop(); } i++; }
return 0; } Any idea how to optimize?Please help! Thank! Edited by author 10.11.2007 23:02 | Should I write online algorithm or it's not necessary? | partisan (Andrey Korotkov) | 1220. Stacks | 10 ноя 2007 17:03 | 1 | |
|
|