QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#603608 | #6723. Grid with Arrows | jay248 | WA | 1ms | 4676kb | C++14 | 1.7kb | 2024-10-01 17:47:18 | 2024-10-01 17:47:21 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
int main(){
int t;
cin>>t;
int ans;
int n, m;
string s;
int w[100005];
int d[100005];
int ch[100005];
int cnt;
int dis;
int cof1, cof2;
int a, b;
for(int c=0; c<t; c++){
cin>>n>>m;
for(int i=0; i<n; i++){
cin>>s;
for(int j=0; j<m; j++){
switch(s[j]){
case 'l': w[i*m+j] = 1; break;
case 'r': w[i*m+j] = 2; break;
case 'u': w[i*m+j] = 3; break;
case 'd': w[i*m+j] = 4; break;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cin>>dis;
d[i*m+j] = dis;
}
}
for(int i=0; i<n*m; i++){
ch[i]=0;
}
ans=1;
cnt=0;
for(int i=0; i<n*m; i++){
switch(w[i]){
case 1: cof1 = 0; cof2 = -1; break;
case 2: cof1 = 0; cof2 = 1; break;
case 3: cof1 = -1; cof2 = 0; break;
case 4: cof1 = 1; cof2 = 0; break;
}
a = i/m + cof1*d[i];
b = i%m + cof2*d[i];
if(a<0 || a>=n || b<0 || b>=m) cnt++;
else{
ch[a*m + b]++;
if(ch[a*m + b] > 1) cnt++;
}
if(cnt > 1){
ans=0; break;
}
}
if(ans==0) {
cout<<"No"<<'\n';
break;
}
cout<<"Yes"<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4636kb
input:
2 2 3 rdd url 2 1 1 1 1 2 2 2 rr rr 1 1 1 1
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 4676kb
input:
1109 5 8 rddddldl drruludl rrldrurd urrrlluu uurrulrl 4 4 1 2 4 3 1 6 1 3 5 1 1 1 3 6 2 4 1 1 2 1 1 1 2 3 4 2 4 3 3 3 4 1 1 2 2 5 1 5 7 9 rdrddrdll urrdruldl ruullrulu drrlrlddl rrrdddlll ruulururl ruurrlluu 7 1 1 1 2 1 2 3 6 1 7 3 1 3 1 2 1 8 2 2 1 2 4 3 1 2 2 2 2 4 1 1 5 3 3 1 3 4 6 1 2 1 2 7 7 6 ...
output:
Yes Yes No
result:
wrong answer expected NO, found YES [2nd token]