QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504674#9110. Zayin and TreeCheek_support#RE 0ms0kbC++203.1kb2024-08-04 14:40:152024-08-04 14:40:15

Judging History

你现在查看的是最新测评结果

  • [2024-08-04 14:40:15]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-04 14:40:15]
  • 提交

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 < 8; 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 >> x2 >> y1 >> y2 >> z1 >> 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];
            }
        }
    }

    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3009
5
4 5 3 4 2
1 2
2 3
3 4
3 5
5
4 4 1 1 2
1 2
2 3
3 4
3 5
10
5 8 1 0 8 7 5 2 0 4
2 4
3 8
3 9
1 2
1 3
3 6
4 5
5 7
6 10
10
6 8 8 4 8 0 6 6 0 2
7 10
1 7
2 9
2 3
3 4
1 5
1 6
6 8
1 2
10
9 0 4 0 4 6 0 2 0 0
1 5
1 3
1 7
2 6
1 2
1 9
1 4
5 8
7 10
10
8 8 1 2 7 4 8 6 0 8
1 6
1 7
1 5
7 9
1 3
1 2
2 10
3 4
1 8...

output:


result: