QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139017 | #4434. Lemurs | ckiseki# | AC ✓ | 2158ms | 152608kb | C++17 | 4.8kb | 2023-08-12 16:29:01 | 2023-08-12 16:29:03 |
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
constexpr int kN = 3000 + 5;
int a[kN][kN], d[kN][kN];
int down[kN][kN], up[kN][kN];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
const int N = k + n + k;
const int M = k + m + k;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
a[i][j] = 1;
d[i][j] = 1 << 30;
}
}
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
for (int j = 0; j < m; ++j) {
a[i + k][j + k] = s[j] == 'x';
}
}
//for (int i = 0; i < N; ++i)
// for (int j = 0; j < M; ++j)
// cout << a[i][j] << " \n"[j + 1 == M];
//cout << "---\n";
for (int i = N - 1; i >= 0; --i) {
for (int j = 0; j < M; ++j) {
if (a[i][j] == 0) {
down[i][j] = 0;
} else {
down[i][j] = 1 << 30;
if (i == N - 1) {
down[i][j] = 1;
} else {
if (j - 1 >= 0)
down[i][j] = min(down[i][j], down[i + 1][j - 1] + 1);
else
down[i][j] = 1;
down[i][j] = min(down[i][j], down[i + 1][j] + 1);
if (j + 1 < M)
down[i][j] = min(down[i][j], down[i + 1][j + 1] + 1);
else
down[i][j] = 1;
}
}
}
}
//for (int i = 0; i < N; ++i)
// for (int j = 0; j < M; ++j)
// cout << down[i][j] << " \n"[j + 1 == M];
//cout << "---\n";
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
if (a[i][j] == 0) {
up[i][j] = 0;
} else {
up[i][j] = 1 << 30;
if (i == 0) {
up[i][j] = 1;
} else {
if (j - 1 >= 0)
up[i][j] = min(up[i][j], up[i - 1][j - 1] + 1);
else
up[i][j] = 1;
up[i][j] = min(up[i][j], up[i - 1][j] + 1);
if (j + 1 < M)
up[i][j] = min(up[i][j], up[i - 1][j + 1] + 1);
else
up[i][j] = 1;
}
}
}
}
//for (int i = 0; i < N; ++i)
// for (int j = 0; j < M; ++j)
// cout << up[i][j] << " \n"[j + 1 == M];
//cout << "---\n";
queue<pair<int, int>> bfs;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int x = i + k, y = j + k;
if (up[x + k][y] > k and down[x - k][y] > k) {
d[x][y] = 0;
bfs.emplace(x, y);
}
}
}
while (not bfs.empty()) {
auto [x, y] = bfs.front();
bfs.pop();
static int dx[] = {0, 0, 1, -1};
static int dy[] = {1, -1, 0, 0};
for (int o = 0; o < 4; ++o) {
const int nx = x + dx[o], ny = y + dy[o];
if (0 > nx or nx >= N)
continue;
if (0 > ny or ny >= M)
continue;
if (d[nx][ny] <= d[x][y] + 1)
continue;
d[nx][ny] = d[x][y] + 1;
bfs.emplace(nx, ny);
}
}
//for (int i = 0; i < N; ++i)
// for (int j = 0; j < M; ++j)
// cout << d[i][j] << " \n"[j + 1 == M];
bool good = true;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int x = i + k, y = j + k;
good &= a[x][y] == (d[x][y] <= k);
}
}
cout << (good ? "TAK" : "NIE") << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 108ms
memory: 104800kb
input:
4000 1 1 1 . 1 1 1 x 1 1 1000 . 1 1 1000 x 1 1000 4 ..........................................xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
TAK TAK TAK TAK TAK NIE NIE TAK NIE TAK NIE NIE TAK TAK NIE TAK TAK NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK NIE NIE TAK TAK TAK NIE NIE NIE TAK TAK NIE NIE TAK NIE NIE NIE TAK NIE NIE NIE TAK NIE NIE NIE NIE TAK NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK NIE NIE NIE TAK TAK ...
result:
ok 4000 lines
Test #2:
score: 0
Accepted
time: 2158ms
memory: 152608kb
input:
36 1000 1000 2 ....xxxx..............xxxxxx..........xx..xxxx......xxxxxxxxxxx.........xxxxxxxxxx...xxxxxx....xxxxxx.......xxxxxx....xxxxxx......................................xx.............xxxxxxxxx......xxxxxxx................xxxxxx..xxxxxx....xxxxxx..............xxxxxxxxxxxxxxxxxxxxxxxxxxxx...x...
output:
TAK NIE NIE TAK TAK NIE TAK NIE NIE TAK TAK NIE NIE NIE NIE TAK NIE TAK TAK TAK TAK NIE TAK NIE NIE TAK NIE TAK NIE NIE NIE TAK TAK NIE NIE NIE
result:
ok 36 lines
Test #3:
score: 0
Accepted
time: 1197ms
memory: 149696kb
input:
41 1000 1000 999 .xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
NIE TAK TAK NIE TAK TAK TAK NIE TAK NIE TAK TAK TAK NIE TAK NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK NIE TAK NIE NIE NIE NIE TAK TAK NIE NIE NIE TAK NIE NIE NIE
result:
ok 41 lines
Extra Test:
score: 0
Extra Test Passed