QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499602 | #6723. Grid with Arrows | Railgun2334 | WA | 164ms | 15344kb | C++20 | 2.0kb | 2024-07-31 16:09:58 | 2024-07-31 16:09:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define ull unsigned long long
void solve()
{
int n,m;
int ans1=0,ans2=0;
cin>>n>>m;
getchar();
vector<vector<int>>a(n+1,vector<int>(m+1));
vector<vector<int>>flag(n+1,vector<int>(m+1));
vector<vector<bool>>ff(n+1,vector<bool>(m+1));
vector<vector<char>>s(n+1,vector<char>(m+1));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>s[i][j];
}
getchar();
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int x=i,y=j;
if(s[x][y]=='r')
{
int dy=y+a[x][y];
if(dy<=m)
{
flag[x][dy]++;
}
}
else if(s[x][y]=='l')
{
int dy=y-a[x][y];
if(dy>=1)
{
flag[x][dy]++;
}
}
else if(s[x][y]=='d')
{
int dx=x+a[x][y];
if(dx<=n)
{
flag[dx][y]++;
}
}
else if(s[x][y]=='u')
{
int dx=x-a[x][y];
if(dx>=1)
{
flag[dx][y]++;
}
}
}
}
int xx=0,yy=0,sum=0;
int f=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(flag[i][j]==flag[1][1])
f++;
if(flag[i][j]==0)
{
xx=i;
yy=j;
sum++;
}
}
}
if(f==n*m)
{
cout<<"No"<<endl;
return;
}
if(sum>=2)
{
cout<<"No"<<endl;
return;
}
int ans=0;
while(!ff[xx][yy])
{
ans++;
ff[xx][yy]=true;
if(s[xx][yy]=='r')
{
int dy=yy+a[xx][yy];
if(dy<=m)
{
yy=dy;
}
}
else if(s[xx][yy]=='l')
{
int dy=yy-a[xx][yy];
if(dy>=1)
{
yy=dy;
}
}
else if(s[xx][yy]=='d')
{
int dx=xx+a[xx][yy];
if(dx<=n)
{
xx=dx;
}
}
else if(s[xx][yy]=='u')
{
int dx=xx-a[xx][yy];
if(dx<=1)
{
xx=dx;
}
}
}
if(ans==n*m)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
int main()
{
ll T = 1;
cin>>T;
while (T--)
{
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
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: 164ms
memory: 15344kb
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 No No No No No No 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 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 [1st token]