|
|
вернуться в форумHELP MY! My program gets WA, but i don't understand, why? #include <iostream.h> const int max = 10010; char *in; int *par; int *zf; int *res; int main(void) { in = new char[max]; par=new int[max]; zf=new int [max]; res=new int [max]; int N,i; cin >> N; for (i=0;i<N;i++) {in[i]=0;par[i]=-1;} for (i=0;i<N;i++) { cin >> zf[i]; zf[i]=zf[i]%N; } int isok=0; for (i=0;i<N;i++) { if (in[zf[i]]==0) {in[zf[i]]=1;par[zf[i]]=i;} if (zf[i]==0) {isok=1; break;} for (int j=0;j<N;j++) { if (in[j]==0 || par[j]==i) continue; int t=j+zf[i]; t=t%N; if (in[t]==0) { in[t]=1; par[t]=i; } if (t==0) {isok=1;break;} } if (isok) break; } if (isok==0) {int a=0; int b=i/a;cout << "0"; return 0;} int pos=0; int k=0; int l=k-zf[par[k]]; if (l<0) l+=N; res[pos]=par[k]; pos++; in[k]=0; k=l; while(1) { if (in[k]==0) break; l=k-zf[par[k]]; if (l<0) l+=N; res[pos]=par[k]; pos++; in[k]=0; k=l; } cout<<pos << "\n"; for (i=pos-1;i>=0;i--) {cout << res[i]+1 << "\n";} delete in; delete par; delete zf; delete res; return 0; } Re: HELP MY! My program gets WA, but i don't understand, why? because of wrong technical output , u should read the task more carefully :) btw , after i modified ur program, it got Time Limit Exceeded :( |
|
|