QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#138935 | #4426. Divided Mechanism | 8BQube# | AC ✓ | 3ms | 3528kb | C++20 | 1.7kb | 2023-08-12 14:34:16 | 2023-08-12 14:34:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define pb push_back
#define ALL(v) v.begin(), v.end()
bool mp[10][10];
void solve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
mp[i][j] = 0;
vector<pii> v;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++)
if (s[j] == '.')
continue;
else if(s[j] == 'A')
mp[i][j] = 1;
else if (s[j] == 'B')
v.pb({i, j});
else
assert(0);
}
const string S = "NSEW";
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
string s;
cin >> s;
#define chk(a, b) ((a) < 0 || (a) >= n || (b) < 0 || (b) >= m || !mp[(a)][(b)])
for (char c : s) {
int x = 0, y = 0;
for (int i = 0; i < 4; i++)
if (c == S[i])
x = dx[i], y = dy[i];
assert(x != 0 || y != 0);
int iter = 0;
while (iter < 20) {
bool ok = true;
for (auto [xx, yy] : v)
if (!chk(xx + x, yy +y)) {
ok = false;
break;
}
if (!ok) break;
for (auto &[xx, yy] : v)
xx += x, yy += y;
iter++;
}
if (iter == 20) {
cout << "TAK\n";
return;
}
}
cout << "NIE\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3528kb
input:
1000 10 9 4 AA...AAAA A......AA A..BBB..A A...B...A A...B...A AA..BBAAA A..BB...A A......AA A...AAAAA AAAAAAAAA WSEN 9 10 4 AAAAAAAAAA A...A....A A......... A..B...B.. AA.BBBBB.. AA..B..B.A AA..A....A AAA.A...AA AAAAAAAAAA ESNE 9 10 7 AAAAAAAAAA A...A....A A......... A..B...B.. AA.BBBBB.. AA..B..B.A...
output:
TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK TAK ...
result:
ok 1000 lines
Extra Test:
score: 0
Extra Test Passed