+ 2

terminated due to timeout

/*Help me find why the program is terminated due to timeout, and correction needed.*/ #include <iostream> using namespace std; int main() { int N,Q,ndx,ndx2; int lastAnswer=0; int q,x,y,z=0,key=0; cin>>N; cin>>Q; int seqList[N][N]; //initialize the seqList to 0. for(int l=0;l<N;l++) { for(int m=0;m<N;m++) { seqList[l][m]=0; } } //Taking the Q quiries, and performing the corresponding operations. for(int i=0;i<Q;i++) { cin>>q; cin>>x; cin>>y; if(q==1) { /*op. 1*/ ndx=(x^lastAnswer)%N; /*op. 2*/ for(int j=0;j<N;j++) { if(seqList[ndx][j]==0) { seqList[ndx][j]=y; break; } j++; } } else { /*op. 1*/ ndx=(x^lastAnswer)%N; /*op. 2*/ while(seqList[ndx][z]!=0) { key++; } ndx2=y%key; cout<<seqList[ndx][ndx2]<<endl; lastAnswer=seqList[ndx][ndx2]; /*op. 3*/ cout<<lastAnswer<<endl; } }

5th Jul 2019, 12:33 PM
Snigdh
Snigdh - avatar
1 Resposta
0
If you are using some online compiler for running your program. Online compiler has some timeout within which your program has to complete it's execution.so there might be some problem with your code and it needs to be optimized. Just look for unnecessary loops which you can remove.
13th Jul 2019, 2:16 AM
siva
siva - avatar