QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#217113 | #6723. Grid with Arrows | shennc11 | WA | 213ms | 16516kb | C++17 | 1.5kb | 2023-10-16 15:06:44 | 2023-10-16 15:06:44 |
Judging History
answer
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
constexpr int maxn = 1e5;
void slove(){
int n,m;
cin>>n>>m;
vector<vector<int> >a(n,vector<int>(m));
vector<vector<int> >p(n,vector<int>(m));
string s[n];
for(int i = 0;i<n;i++){
cin>>s[i];
}
int pos = 1;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
cin>>a[i][j];
p[i][j] = pos++;
}
}
pos = 1;
auto check = [&](int x,int y){
if(x >=n || x<0)return false;
if(y>=m || y<0)return false;
return true;
};
vector<int> g[n*m+5];
vector<int> d(n*m+5,0);
pos = 1;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
int dx = i,dy = j;
if(s[i][j] == 'u'){
dx-=a[i][j];
}else if(s[i][j] =='d'){
dx+=a[i][j];
}else if(s[i][j] == 'l'){
dy-=a[i][j];
}else if(s[i][j] == 'r'){
dy+=a[i][j];
}
if(check(dx,dy)){
g[pos].push_back(p[dx][dy]);
d[p[dx][dy]] ++;
}
pos++;
}
}
auto bfs = [&](int x){
vector<int>st(n*m + 7);
queue<int>q;
st[x] = 1;
int tit = n*m;
q.push(x);
while(!q.empty()){
tit--;
int u = q.front();
q.pop();
for(auto &i:g[u]){
if(!st[i]){
q.push(i);
st[i] = 1;
}
}
}
if(tit== 0)return true;
else return false;
};
bool flag = 0;
for(int i = 1;i<=n*m;i++){
if(d[i] ==0){
if(bfs(i)){
flag = 1;
}
}
}
if(flag)puts("YES");
else puts("NO");
}
int main(){
int t;cin>>t;
while(t--)
slove();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 213ms
memory: 16516kb
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:
NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES NO YES NO NO YES NO NO NO YES YES NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO YES YES NO...
result:
wrong answer expected YES, found NO [1st token]