QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#243213 | #6723. Grid with Arrows | gzzz# | WA | 59ms | 10468kb | C++20 | 1.6kb | 2023-11-07 22:08:54 | 2023-11-07 22:08:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
string mp[maxn];
vector<vector<int> > s;
int in[maxn],out[maxn],fa[maxn];
int find(int x){
if(fa[x]==x) {
return x;
}
return fa[x]=find(fa[x]);
}
void unit(int x,int y){
fa[find(x)]=find(y);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;cin>>t;
while(t--) {
int n,m;
cin>>n>>m;
for(int i=0;i<n*m;i++){
fa[i]=i;
}
s.clear();
for(int i=0;i<n;i++){
mp[i].clear();
cin>>mp[i];
}
for(int i=1;i<=n;i++){
vector<int> tmp;
for(int j=1;j<=m;j++){
int x;cin>>x;
tmp.push_back(x);
}
s.push_back(tmp);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int fr=i*m+j;
int tox=i,toy=j;
if(mp[i][j]=='r') {
toy+=s[i][j];
}
else if(mp[i][j]=='l'){
toy-=s[i][j];
}
else if(mp[i][j]=='u'){
tox-=s[i][j];
}
else {
tox+=s[i][j];
}
if(tox<0||tox>=n||toy<0||toy>=m) {
continue;
}
else {
int to=tox*m+toy;
in[to]++;
out[fr]++;
unit(fr,to);
}
}
}
int num1=0,num2=0;
for(int i=0;i<=(n-1)*m+(m-1);i++){
if(in[i]>out[i]) {
num1++;
}
else if(out[i]>in[i]){
num2++;
}
}
if(num1!=num2){
cout<<"No\n";
}
else {
if(num1==1||num1==0) {
bool flag=true;
for(int i=1;i<n*m&&flag;i++){
if(find(i)!=find(0)) {
flag=false;
}
}
if(flag) cout<<"Yes\n";
else cout<<"No\n";
}
else {
cout<<"No\n";
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6748kb
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: 59ms
memory: 10468kb
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 No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...
result:
wrong answer expected YES, found NO [5th token]