zarif_2002's blog

By zarif_2002, history, 10 months ago, , please tell me why they show me wrong answer.

here

i used this technique. if a = 1, go right. if a = -1, go left, if b = 1, go up, if b = -1, go down.

used ara to store 0 if it is not travelled and store 1 if it is travelled.

include<string.h>

int main(){

int a,b,i,j,m,n,t,len,ara,p,q,r;

char s;

scanf("%d",&t);

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

scanf("%d %d\n", &m, &n);

r = 0;

gets(s);

for(p = 0; p < 64; p++){

for(q = 0; q < 64; q++){

ara[p][q] = 0;
}
}
ara[m][n] = 1;

len = strlen(s);

a = 0, b = 1;

for(j = 0; j < len; j++){

if(s[j] == 'F'){

if(b == 1){

n++;
}
else if(b == -1){

n--;
}
else if(a == 1){

m++;
}
else if(a == -1){

m--;
}
if(ara[m][n] == 1){

r++;
}
else{

ara[m][n] = 1;
}
}
else if(s[j] == 'R'){

if(b == 1){

b = 0;

a = 1;
}
else if(b == -1){

b = 0;

a = -1;
}
else if(a == 1){

a = 0;

b = -1;
}
else if(a == -1){

a = 0;

b = 1;
}
}
else{

if(a == 1){

a = 0;

b = 1;
}
else if(a == -1){

a = 0;

b = -1;
}
else if(b == 1){

b = 0;

a = -1;
}
else if(b == -1){

b = 0;

a = 1;
}
}
}
printf("Case #%d: %d %d %d\n",i + 1,m,n,r);
}
return 0;

}  Comments (5)
 » LoOoOooLoOoOoOoooOLooOoOoOoOooL. ROFL. LMAO. NO.
•  » » what. when, i stuck on a problem and you say lol. please, find my mistake as they are giving me WA
•  » » » LoOoOooLoOoOoOoooOLooOoOoOoOooL. ROFL. LMAO. Google for AC solutions, generate random test cases and compare it against the output of your own program. You'll find the bug yourself.
 » 10 months ago, # | ← Rev. 2 →   One possible thing: The question asks for the number of locations visited more than once, not how many times you visit an already-seen location. So if you visit a single square three times and all other squares at most once, the answer is 1, not 2.
•  » » thanks bro