QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#138917 | #4426. Divided Mechanism | ckiseki# | AC ✓ | 3ms | 3544kb | C++17 | 2.2kb | 2023-08-12 14:14:30 | 2023-08-12 14:14:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int cnt = sizeof...(T);
(..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
cerr << (f++ ? ", " : "") << *L;
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
int dx[256], dy[256];
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<pair<int,int>> A, B;
for (int i = 0; i < n; i++) {
string g;
cin >> g;
for (int j = 0; j < m; j++) {
if (g[j] == 'A') {
A.emplace_back(i, j);
} else if (g[j] == 'B') {
B.emplace_back(i, j);
}
}
}
vector<vector<int>> G(n * 2, vector<int>(m * 2));
for (int i = 0; i < n * 2; i++) {
orange(all(G[i]));
}
for (auto [x1, y1]: A) {
for (auto [x2, y2]: B) {
G[x1 - x2 + n][y1 - y2 + m] = true;
}
}
string s;
cin >> s;
int x = n, y = m;
assert (G[x][y] == false);
for (int i = 0; i < n * 2; i++) {
orange(all(G[i]));
}
const auto ok = [&](int x, int y) {
return x >= 0 && x < n * 2 && y >= 0 && y < m * 2;
};
for (char c: s) {
int DX = dx[c], DY = dy[c];
debug(DX, DY, c);
while (ok(x, y) && (!ok(x+DX, y+DY) || G[x+DX][y+DY] == false)) {
x += DX;
y += DY;
}
if (x < 0 || x >= n * 2 || y < 0 || y >= m * 2) {
cout << "TAK\n";
return;
}
}
debug(x, y);
cout << "NIE\n";
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
dx['S'] = 1;
dy['S'] = 0;
dx['N'] = -1;
dy['N'] = 0;
dx['E'] = 0;
dy['E'] = 1;
dx['W'] = 0;
dy['W'] = -1;
int T;
cin >> T;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3544kb
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