QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#504656 | #9108. Zayin and Obstacles | PlentyOfPenalty# | AC ✓ | 213ms | 26492kb | C++20 | 2.4kb | 2024-08-04 14:32:47 | 2024-08-04 14:32:48 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define rep(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)
#define per(i, l, r) for (int i = (l), i##end = (r); i >= i##end; --i)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define log(...) (void(0))
#define endl '\n'
#endif
using namespace std;
using ll = long long;
using lf = long double;
using ull = unsigned long long;
const int N = 1e2 + 9;
const int mov[8][3] = {
{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1},
};
int T, n, m, l, r, s[N][N][N], dis[N][N][N];
struct atom {
int x, y, z;
} q[N * N * N], a, b;
int solve() {
if (s[a.x][a.y][a.z] || s[b.x][b.y][b.z]) return -1;
q[l = r = 0] = a;
dis[a.x][a.y][a.z] = 1;
while (l <= r) {
auto u = q[l++];
// log("> %d %d %d >> dis=%d\n", u.x, u.y, u.z, dis[u.x][u.y][u.z]);
for (int i = 0; i < 8; i++) {
auto v = u;
v.x += mov[i][0];
v.y += mov[i][1];
v.z += mov[i][2];
if (1 <= v.x && v.x <= n && 1 <= v.y && v.y <= n && 1 <= v.z && v.z <= n && !s[v.x][v.y][v.z] && !dis[v.x][v.y][v.z]) {
dis[v.x][v.y][v.z] = dis[u.x][u.y][u.z] + 1;
q[++r] = v;
}
}
}
return dis[b.x][b.y][b.z] - 1;
}
int main() {
#ifdef memset0
freopen("H.in", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
cin >> T;
while (T--) {
cin >> n >> m;
rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) { s[i][j][k] = dis[i][j][k] = 0; }
rep(k, 1, m) {
int x0, x1, y0, y1, z0, z1;
cin >> x0 >> y0 >> z0 >> x1 >> y1 >> z1;
s[x0][y0][z0]++;
s[x1 + 1][y0][z0]--;
s[x0][y1 + 1][z0]--;
s[x0][y0][z1 + 1]--;
s[x1 + 1][y1 + 1][z0]++;
s[x1 + 1][y0][z1 + 1]++;
s[x0][y1 + 1][z1 + 1]++;
s[x1 + 1][y1 + 1][z1 + 1]--;
}
rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) {
if (i) s[i][j][k] += s[i - 1][j][k];
if (j) s[i][j][k] += s[i][j - 1][k];
if (k) s[i][j][k] += s[i][j][k - 1];
if (i && j) s[i][j][k] -= s[i - 1][j - 1][k];
if (i && k) s[i][j][k] -= s[i - 1][j][k - 1];
if (j && k) s[i][j][k] -= s[i][j - 1][k - 1];
if (i && j && k) s[i][j][k] += s[i - 1][j - 1][k - 1];
}
// rep(i, 1, n) rep(j, 1, n) rep(k, 1, n) log("a[%d][%d][%d] = %d\n", i, j, k, s[i][j][k]);
cin >> a.x >> a.y >> a.z >> b.x >> b.y >> b.z;
cout << solve() << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9776kb
input:
3 3 0 1 1 1 3 3 3 3 1 2 1 1 2 3 3 1 1 1 3 3 3 3 3 2 1 1 2 2 3 1 1 2 2 3 2 1 2 2 3 3 2 1 1 1 1 1 3
output:
6 -1 14
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 24ms
memory: 18460kb
input:
5 19 27 2 1 1 2 18 19 4 2 1 4 19 19 6 1 1 6 18 19 8 2 1 8 19 19 10 1 1 10 18 19 12 2 1 12 19 19 14 1 1 14 18 19 16 2 1 16 19 19 18 1 1 18 18 19 1 1 2 18 19 2 2 1 4 19 19 4 1 1 6 18 19 6 2 1 8 19 19 8 1 1 10 18 19 10 2 1 12 19 19 12 1 1 14 18 19 14 2 1 16 19 19 16 1 1 18 18 19 18 1 2 2 19 19 2 1 2 4 ...
output:
1998 15998 53998 127998 249998
result:
ok 5 lines
Test #3:
score: 0
Accepted
time: 79ms
memory: 18332kb
input:
5 99 147 2 1 1 2 98 99 4 2 1 4 99 99 6 1 1 6 98 99 8 2 1 8 99 99 10 1 1 10 98 99 12 2 1 12 99 99 14 1 1 14 98 99 16 2 1 16 99 99 18 1 1 18 98 99 20 2 1 20 99 99 22 1 1 22 98 99 24 2 1 24 99 99 26 1 1 26 98 99 28 2 1 28 99 99 30 1 1 30 98 99 32 2 1 32 99 99 34 1 1 34 98 99 36 2 1 36 99 99 38 1 1 38 9...
output:
132878 2596 227782 37198 90672
result:
ok 5 lines
Test #4:
score: 0
Accepted
time: 22ms
memory: 16208kb
input:
5 99 1000 2 1 1 2 98 99 4 2 1 4 99 99 6 1 1 6 98 99 8 2 1 8 99 99 10 1 1 10 98 99 12 2 1 12 99 99 14 1 1 14 98 99 16 2 1 16 99 99 18 1 1 18 98 99 20 2 1 20 99 99 22 1 1 22 98 99 24 2 1 24 99 99 26 1 1 26 98 99 28 2 1 28 99 99 30 1 1 30 98 99 32 2 1 32 99 99 34 1 1 34 98 99 36 2 1 36 99 99 38 1 1 38 ...
output:
4998 4998 4998 4998 4998
result:
ok 5 lines
Test #5:
score: 0
Accepted
time: 28ms
memory: 22316kb
input:
5 19 1000 2 1 1 2 18 19 4 2 1 4 19 19 6 1 1 6 18 19 8 2 1 8 19 19 10 1 1 10 18 19 12 2 1 12 19 19 14 1 1 14 18 19 16 2 1 16 19 19 18 1 1 18 18 19 4 13 10 4 19 12 6 5 5 6 6 18 6 16 4 6 18 11 8 6 10 8 17 19 14 10 7 14 17 12 2 4 4 2 5 15 4 5 10 4 7 17 12 1 2 12 2 9 12 8 10 12 18 15 16 19 2 16 19 8 8 1 ...
output:
-1 798 1906 3198 4998
result:
ok 5 lines
Test #6:
score: 0
Accepted
time: 213ms
memory: 26492kb
input:
5 100 0 92 81 37 11 85 14 100 0 16 48 91 61 65 58 100 0 87 25 52 83 7 45 100 0 80 95 16 62 5 80 100 0 33 33 50 48 82 3
output:
108 95 29 172 111
result:
ok 5 lines