QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#504679#9108. Zayin and ObstaclesAnotherDayofSun#AC ✓108ms13196kbC++201.8kb2024-08-04 14:44:412024-08-04 14:44:42

Judging History

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

  • [2024-08-04 14:44:42]
  • 评测
  • 测评结果:AC
  • 用时:108ms
  • 内存:13196kb
  • [2024-08-04 14:44:41]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define foR(i,j,k) for(int i=(j);i>=(k);i--) 
#define vi vector<int>
#define pb push_back
#define pii pair<int,int> 
#define mkp make_pair
#define SZ(x) ((int)x.size())

using namespace std;
inline int read() {
	char c;int res=0;bool flag=0;
	while(c=getchar(),c<48)(c=='-')&&(flag=1);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	flag&&(res=-res); return res; 
}
const int MN=105; 
int n,vis[MN][MN][MN],m,sum[MN][MN][MN]; 
int dx[6]={1,-1,0,0,0,0};
int dy[6]={0,0,1,-1,0,0};
int dz[6]={0,0,0,0,1,-1}; 
struct ele {
	int x,y,z; 
	ele(){} ele(int X,int Y,int Z):x(X),y(Y),z(Z){}	
}; 
void works() {
	n=read(),m=read();
	memset(vis,0,sizeof(vis)); memset(sum,0,sizeof(sum)); 
	For(i,1,n) For(j,1,n) For(k,1,n) vis[i][j][k]=-1;   
	For(i,1,m) {
		int x1=read(),y1=read(),z1=read(),x2=read(),y2=read(),z2=read();
		For(x,x1,x2) {
			sum[x][y1][z1]++; 
			sum[x][y1][z2+1]--; 
			sum[x][y2+1][z1]--; 
			sum[x][y2+1][z2+1]++; 
		}	
	}
	For(x,1,n) {
		For(y,1,n) For(z,1,n) {
			sum[x][y][z]+=sum[x][y-1][z]+sum[x][y][z-1]-sum[x][y-1][z-1]; 
			if(sum[x][y][z]) vis[x][y][z]=1; 	
		}
	}
	int sx=read(),sy=read(),sz=read(),ex=read(),ey=read(),ez=read();
	queue<ele>q; q.push(ele(sx,sy,sz)); vis[sx][sy][sz]=0; 
	while(SZ(q)) {
		ele it=q.front(); q.pop();
		int x=it.x,y=it.y,z=it.z; 
		For(i,0,5) {
			int nx=it.x+dx[i],ny=it.y+dy[i],nz=it.z+dz[i]; 
			if(vis[nx][ny][nz]!=-1) continue; 
			vis[nx][ny][nz]=vis[x][y][z]+1; 
			
			q.push(ele(nx,ny,nz)); 	
		}
	}
	if(vis[ex][ey][ez]!=-1) printf("%d\n",vis[ex][ey][ez]); 
	else printf("-1\n"); 
}
signed main() {
	#ifdef wasa855
		freopen("pro.in","r",stdin); 
		freopen("pro.out","w",stdout); 
	#endif
	int T=read(); 
	while(T--) {
		works(); 	
	}
	return 0; 	
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 13032kb

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: 15ms
memory: 12776kb

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: 13004kb

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: 11ms
memory: 12704kb

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: 23ms
memory: 13008kb

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: 108ms
memory: 13196kb

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