QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350029 | #6723. Grid with Arrows | wudibaolong# | AC ✓ | 56ms | 10000kb | C++14 | 1.6kb | 2024-03-10 12:51:45 | 2024-03-10 12:51:46 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>
#include<queue>
#define ll long long
const int N=1e6+10;
const ll mod=1e9+7;
ll read(){
ll s = 0, f = 1; char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return s * f;
}
using namespace std;
char s[N];
int sum,n,m;
int fa[N],ru[N];
int find(int x){
return x==fa[x]? x:fa[x]=find(fa[x]);
}
void merge(int x,int y){
int u=find(x);
int v=find(y);
if(u!=v){
fa[v]=u;
}
}
void init(){
sum=n*m;
for(int i=1;i<=sum;i++) fa[i]=i,ru[i]=0;
return ;
}
int locate(char ch,int i,int j,int u,int ans){
int v=0;
if(ch=='u'&&i-ans>=1)
v=u-ans*m;
if(ch=='d'&&i+ans<=n)
v=u+ans*m;
if(ch=='l'&&j-ans>=1)
v=u-ans;
if(ch=='r'&&j+ans<=m)
v=u+ans;
return v;
}
void solve(){
n=read();m=read();
init();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>s[(i-1)*m+j];
}
//for(int i=1;i<=sum;i++) cout<<s[i];
int ans,u,v;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans=read();
u=(i-1)*m+j;
v=locate(s[u],i,j,u,ans);
if(v){
merge(u,v);
ru[v]++;
}
}
}
int f=find(1);
for(int i=2;i<=sum;i++){
if(find(i)!=f){
cout<<"No"<<endl;
return;
}
}
ans=0;
for(int i=1;i<=sum;i++){
if(ru[i]==0) ans++;
if(ans>=2) {cout<<"No"<<endl;return ;}
}
cout<<"Yes"<<endl;
return ;
}
int main (){
int T;cin>>T;
while(T--){
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7792kb
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: 0
Accepted
time: 56ms
memory: 10000kb
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 Yes No Yes Yes Yes Yes No No No Yes Yes No Yes No Yes No No No Yes Yes No Yes Yes No Yes No No Yes No No Yes Yes Yes No No Yes Yes Yes No Yes No Yes No Yes Yes No Yes No Yes No Yes Yes No No Yes No Yes Yes Yes Yes No Yes Yes No Yes Yes No No Yes Yes No No Yes Yes No No Yes Yes Yes Yes Y...
result:
ok 1109 token(s): yes count is 602, no count is 507