QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#499488 | #6723. Grid with Arrows | buzhijingdi | RE | 1ms | 7680kb | C++14 | 2.0kb | 2024-07-31 14:55:25 | 2024-07-31 14:55:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6 + 9;
const int M = 1e3 + 9;
const int mod = 1e9 + 7;
#define eps 1e-5
#define inf 2e18
int a[N];
int vis[N];
int n,m;
char s[M][M];
int p[M][M];
void solve()
{
cin>>n>>m;
// for(int i=1;i<=n;++i) a[i]=0;
int cnt=0,sum=0;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
cin>>s[i][j];
}
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
cin>>p[i][j];
if(s[i][j]=='u')
{
if(i - p[i][j] >= 1) sum++;
if(i - p[i][j] >= 1 && s[i - p[i][j]][j] != 'u' && s[i - p[i][j]][j]!='d')
{
if(!vis[i - p[i][j]]) cnt++;
vis[i - p[i][j]]++;
}
}
else if(s[i][j]=='d')
{
if(i + p[i][j] <= n) sum++;
if(i + p[i][j] <= n && s[i + p[i][j]][j] != 'u' && s[i + p[i][j]][j]!='d')
{
if(!vis[i + p[i][j]]) cnt++;
vis[i + p[i][j]]++;
}
}
}
if(cnt != n)
{
cout<<"No"<<'\n';
return ;
}
// cout<<sum<<'\n';
bitset<M> st;
for(int i=1;i<=n;++i)
{
st.reset();
for(int j=1;j<=m;++j)
{
if(s[i][j]=='r' && p[i][j] + j <=m && !st[p[i][j] + j])
{
st[p[i][j] + j]=1;
sum++;
}
else if(s[i][j]=='l' && j - p[i][j] >= 1 && !st[j - p[i][j] ])
{
st[j - p[i][j] ]=1;
sum++;
}
}
}
if(sum >= n*m - 1) cout<<"Yes"<<'\n';
else cout<<"No"<<'\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1; cin>>_;
while (_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7680kb
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 ...