Fun With Rotation(WA)

, ,

#include<stdio.h>

int main(){

  long n,m,i=0,k=0,j=0;

  long long A[100000];

   char a;

  scanf("%ld%ld",&n,&m);

  for(i=0;i<n;i++){

     scanf("%ld",A+i);

  }

   i=0;j=n-1;

while(m-- > 0){

          fflush(stdin);
   scanf("%c%ld",&a,&k);
   
             if(a== 'C'){
                      i=(i+k)%n;
                      j=(j+k)%n;
                     // printf("i=%ld j=%ld\n",i,j);
             }
             else if (a=='A'){
                     i=(i+n-k)%n;
                     j=(j+n-k)%n;
                                           //    printf("i=%ld j=%ld\n",i,j);
             }
             else{
                     // printf("i=%ld j=%ld\n",i,j);
                      printf("%lld\n",A[(i+k-1)%n]);
             }
            
   
   
   //printf("The value of m:%ld\n",m);
}

//getch();
return 0;

}

You are getting wrong answer for the following testcase:

5 10
5 6 1 2 5
R 5
C 1
A 3
A 5
R 4
R 1
A 5
R 1
R 1
R 3

See here.

Correct answers are:

5  
6
2
2
2
5
1 Like

your sample case is giving the correct ans.I have checked it myself just now

It may be correct on your machine but not on Codechef. See output section in the ideone link. This is the output of your solution on codechef. Codechef’s online judge and Ideone’s judge are same.

your link is showing the one of the value if ans is 9!
But i m getting all the ans correct

yes, that’s right. One extra 9 is printed which is not expected in output. That’s why WA. I’m trying to check few more things. I will reply in few minutes.

yes, your logic was correct. I have made few changes and written comments for them. See your AC solution. CodeChef: Practical coding for everyone

yes i gt it.I m using Dev C++ n thankU.
Can be provide me the link for taking faster i/p.i have people taking i/p using getchar_unlocked().I m unaware of it
plz help if possible

Actually there was a problem while scanning a character and an integer in this line scanf(“%c%d,&a,&k). I just changed it to scanf(” %c %d,&a,&k), it got AC. CodeChef: Practical coding for everyone . There is ‘\n’ at the end of every line. So while scanning character ‘\n’ was scanned , created whole mess. Now that extra space will take care of ‘\n’.

yes.There there is a problem with buffer.thats why i have used ffflush(stdin).no way Thankx

For fast i/o see this link https://github.com/shivam217/CP/blob/master/fast%20_input_output.cpp