QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499535 | #6723. Grid with Arrows | Railgun2334 | RE | 0ms | 3584kb | C++20 | 1.5kb | 2024-07-31 15:28:52 | 2024-07-31 15:28:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define re read()
#define MOD 998244353
#define i128 __int128
#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,0));
vector<vector<bool>>flag(n+1,vector<bool>(m+1,0));
vector<vector<char>>s(n+1,vector<char>(m+1,0));
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;
while(!flag[x][y])
{
flag[x][y]=true;
if(s[x][y]=='r')
{
int dy=y+a[x][y];
if(dy<=m)
{
y=dy;
}
else
{
ans1++;
}
}
else if(s[x][y]=='l')
{
int dy=y-a[x][y];
if(dy>=1)
{
y=dy;
}
else
{
ans1++;
}
}
else if(s[x][y]=='d')
{
int dx=x+a[x][y];
if(dx<=n)
{
x=dx;
}
else
{
ans1++;
}
}
else if(s[x][y]=='u')
{
int dx=x-a[x][y];
if(dx<=1)
{
x=dx;
}
else
{
ans1++;
}
}
if(x==i&&y==j)
ans2++;
}
}
}
//cout<<ans1<<" "<<ans2<<endl;
if(ans1+ans2==1)
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: 3584kb
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
Runtime Error
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