QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#504687 | #9108. Zayin and Obstacles | Cheek_support# | AC ✓ | 116ms | 14004kb | C++20 | 3.1kb | 2024-08-04 14:48:41 | 2024-08-04 14:48:43 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define DEBUG_VAR(x) { cerr << "* "#x" = " << x << endl; }
#define DEBUG_ARR(arr, l, r) { \
cerr << "* "#arr"[" << l << ", " << r << "]:"; \
for(auto it = l, itr = r; it <= itr; it++) \
cerr << arr[it] << ", "; \
cerr << endl; \
}
#define DEBUG_FMT(...) { cerr << "* "; fprintf(stderr, __VA_ARGS__); }
#define DEBUG_HERE { DEBUG_FMT("Passing [%s] in LINE %d\n", __FUNCTION__, __LINE__); }
#define y1 y_1
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const int N = 105, M = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const int dx[] = {1, -1, 0, 0, 0, 0}, dy[] = {0, 0, -1, 1, 0, 0}, dz[] = {0, 0, 0, 0, -1, 1};
int n, m;
int a[N][N][N];
int dis[N][N][N];
bool vis[N][N][N];
int sx, sy, sz, tx, ty, tz;
void bfs()
{
queue<tuple<int, int, int>> q;
dis[sx][sy][sz] = 0;
vis[sx][sy][sz] = true;
q.emplace(sx, sy, sz);
while(q.size()) {
auto [x, y, z] = q.front(); q.pop();
for(int i = 0; i < 6; i++) {
int nx = x + dx[i], ny = y + dy[i], nz = z + dz[i];
if(nx < 1 || nx > n || ny < 1 || ny > n || nz < 1 || nz > n)
continue;
if(vis[nx][ny][nz])
continue;
if(a[nx][ny][nz]) continue;
dis[nx][ny][nz] = dis[x][y][z] + 1;
vis[nx][ny][nz] = true;
q.emplace(nx, ny, nz);
}
}
}
void solve()
{
cin >> n >> m;
for(int i = 0; i <= n + 1; i++) {
for(int j = 0; j <= n + 1; j++) {
for(int k = 0; k <= n + 1; k++) {
a[i][j][k] = 0;
dis[i][j][k] = INF;
vis[i][j][k] = false;
}
}
}
for(int i = 1; i <= m; i++) {
int x1, x2, y1, y2, z1, z2;
cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
a[x1][y1][z1]++;
a[x2 + 1][y1][z1]--;
a[x1][y2 + 1][z1]--;
a[x1][y1][z2 + 1]--;
a[x2 + 1][y2 + 1][z1]++;
a[x2 + 1][y1][z2 + 1]++;
a[x1][y2 + 1][z2 + 1]++;
a[x2 + 1][y2 + 1][z2 + 1]--;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
for(int k = 1; k <= n; k++) {
a[i][j][k] +=
a[i - 1][j][k]
+a[i][j - 1][k]
+a[i][j][k - 1]
-a[i - 1][j - 1][k]
-a[i - 1][j][k - 1]
-a[i][j - 1][k - 1]
+a[i - 1][j - 1][k - 1];
// DEBUG_FMT("a(%d, %d, %d) = %d\n", i, j, k, a[i][j][k]);
}
}
}
cin >> sx >> sy >> sz >> tx >> ty >> tz;
bfs();
if(dis[tx][ty][tz] == INF) {
cout << "-1" << endl;
} else {
cout << dis[tx][ty][tz] << endl;
}
}
int main()
{
// freopen("1.in", "r", stdin);
ios::sync_with_stdio(false); cin.tie(nullptr);
int T; cin >> T;
while(T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5720kb
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: 17ms
memory: 13472kb
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: 36ms
memory: 13596kb
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: 18ms
memory: 13616kb
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: 24ms
memory: 13556kb
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: 116ms
memory: 14004kb
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