QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214179 | #6723. Grid with Arrows | yyyyy3 | WA | 3ms | 8936kb | C++14 | 1.6kb | 2023-10-14 17:45:55 | 2023-10-14 17:45:55 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define _ int _T; cin >> _T; while(_T --)
#define int long long
using namespace std;
const int N = 1e5 + 10;
const int MAX = 1e3 + 10;
int n,m;
string s[N];
vector<int> g[N];
int r[N];
bool st[MAX];
void bfs(){
queue<int> q;
for(int i = 1;i <= n * m;i ++){
if(!r[i]){
q.push(i);
break;
}
} if(!q.size()) q.push(1);
int ans = 0;
while(q.size()){
int t = q.front();
q.pop();
if(st[t]) continue;
st[t] = true;
// cout << t << "TTT" << endl;
ans ++;
for(auto x : g[t]){
if(!st[x])
q.push(x);
}
}// cout << ans << endl;
if(ans != n * m) cout << "NO" << endl;
else cout << "YES" << endl;
}
void solve(){
int pos = 1;
cin >> n >> m;
for(int i = 1;i <= n * m;i ++){
st[i] = false;
g[i].clear();
r[i] = 0;
}
for(int i = 1;i <= n;i ++){
cin >> s[i];
}
for(int i = 1;i <= n;i ++){
for(int j = 0;j < m;j ++){
int a; cin >> a;
if(s[i][j] == 'r' && j + 1 + a <= m){
g[pos].push_back(pos + a);
r[pos + a] ++;
}
if(s[i][j] == 'l' && j + 1 - a >= 1){
g[pos].push_back(pos - a);
r[pos - a] ++;
}
if(s[i][j] == 'u' && i - a >= 1){
g[pos].push_back(pos - a * m);
r[pos - a * m] ++;
}
if(s[i][j] == 'd'){
g[pos].push_back(pos + a * m);
r[pos + a * m] ++;
}
pos ++;
}
}
bfs();
for(int i = 1;i <= n * m;i ++){
for(auto t : g[i]){
cout << t << " " << r[t] << " " << i << " " << t ;
} cout << endl;
}
}
signed main(){
// fast();
_
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 8936kb
input:
2 2 3 rdd url 2 1 1 1 1 2 2 2 rr rr 1 1 1 1
output:
YES 3 1 1 3 5 1 2 5 6 2 3 6 1 1 4 1 6 2 5 6 4 1 6 4 NO 2 1 1 2 4 1 3 4
result:
wrong output format YES or NO expected, but 3 found [2nd token]