QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504759#9108. Zayin and Obstaclesurayaha_yahaura#AC ✓155ms17556kbC++142.1kb2024-08-04 15:41:222024-08-04 15:41:23

Judging History

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

  • [2024-08-04 15:41:23]
  • 评测
  • 测评结果:AC
  • 用时:155ms
  • 内存:17556kb
  • [2024-08-04 15:41:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int read(){
    char c;int res=0;
    while(!isdigit(c=getchar()));
    res=c-'0';
    while(isdigit(c=getchar()))
        res=res*10+c-'0';
    return res;
}
const int N=105;
const int M=1005;

#define out(x) cerr<<#x<<'='<<x<<' '
#define outln(x) cerr<<#x<<"="<<x<<"\n"
#define sz(x) (int)(x).size()
typedef long long ll;
const int inf=(int)1e9;
int ss[N][N][N],s[N][N][N];
int n,m;
int dx[]={1,-1,0,0,0,0};
int dy[]={0,0,1,-1,0,0};
int dz[]={0,0,0,0,1,-1};
int d[N][N][N];

void init(){
    n=read(); m=read();
    memset(s,0,sizeof(s));
    memset(ss,0,sizeof(ss));
    for(int i=1;i<=m;i++){
        int a=read(),b=read(),c=read(),d=read(),e=read(),f=read();
        ss[a][b][c]++; 
        ss[d+1][b][c]--;
        ss[a][e+1][c]--;
        ss[a][b][f+1]--;
        ss[d+1][e+1][c]++;
        ss[d+1][b][f+1]++;
        ss[a][e+1][f+1]++;
        ss[d+1][e+1][f+1]--;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                s[i][j][k]=ss[i][j][k]+s[i-1][j][k]+s[i][j-1][k]+s[i][j][k-1]-s[i-1][j-1][k]-s[i-1][j][k-1]-s[i][j-1][k-1]+s[i-1][j-1][k-1];
                // out(i); out(j); out(k); outln(s[i][j][k]);
            }
        }
    }
}
int sx,sy,sz,ex,ey,ez;
struct node{
    int x,y,z;
};
int valid(int x,int y,int z){
    if(d[x][y][z]<inf) return 0;
    if(s[x][y][z]) return 0;
    if(x<1||x>n||y<1||y>n||z<1||z>n) return 0;
    return 1;
}

void bfs(){
    memset(d,0x3f,sizeof(d));
    d[sx][sy][sz]=0; 
    queue<node> q; q.push({sx,sy,sz});
    while(!q.empty()){
        node u=q.front(); q.pop();
        for(int i=0;i<6;i++){
            int xx=u.x+dx[i],yy=u.y+dy[i],zz=u.z+dz[i];
            if(!valid(xx,yy,zz)) continue;
            d[xx][yy][zz]=d[u.x][u.y][u.z]+1;
            q.push({xx,yy,zz});
        }
    }
}

void solve(){
    sx=read(),sy=read(),sz=read(),ex=read(),ey=read(),ez=read();
    bfs();
    if(d[ex][ey][ez]<inf) printf("%d\n",d[ex][ey][ez]);
    else puts("-1");
}

int main(){
    int T=read();
    while(T--){init(); solve();}
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 17328kb

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: 18ms
memory: 17300kb

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: 63ms
memory: 17312kb

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: 19ms
memory: 17296kb

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: 26ms
memory: 17300kb

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: 155ms
memory: 17556kb

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