QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#504697#9108. Zayin and ObstaclesLavender_Field#AC ✓147ms13124kbC++202.3kb2024-08-04 14:58:442024-08-04 14:58:44

Judging History

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

  • [2024-08-04 14:58:44]
  • 评测
  • 测评结果:AC
  • 用时:147ms
  • 内存:13124kb
  • [2024-08-04 14:58:44]
  • 提交

answer

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define Mp make_pair
#define PR pair<int, pair<int,int> >
#define fi first
#define se second
using namespace std;

int rd() {
	int r = 0; bool w = false; char ch = getchar();
	while( ch < '0' || ch > '9' ) w = !(ch^45), ch = getchar();
	while( ch >= '0' && ch <= '9' ) r = (r<<1) + (r<<3) + (ch^48), ch = getchar();
	return w ? -r : r;
}

#define MAXN 100
int n, m;
int r[MAXN+5][MAXN+5][MAXN+5];
int vis[MAXN+5][MAXN+5][MAXN+5];
int sx, sy, sz, tx, ty, tz;
queue<pair<int, pair<int,int> > > q;
int dx[] = {0, 1, -1, 0, 0, 0, 0};
int dy[] = {0, 0, 0, 1, -1, 0, 0};
int dz[] = {0, 0, 0, 0, 0, 1, -1};
void solve() {
	n = rd(), m = rd();
	memset(r,0,sizeof(r));
	memset(vis,-1,sizeof(vis));
	FOR(i,1,m) {
		int a = rd(), b = rd(),
			c = rd(), d = rd(),
			e = rd(), f = rd();
//		r[d][e][f] += 1;
//		r[d][e][c-1] -= 1;
//		r[a-1][e][f] -= 1;
//		r[d][b-1][f] -= 1;
//		r[a-1][b-1][f] += 1;
//		r[a-1][e][c-1] += 1;
//		r[d][b-1][c-1] += 1;
//		r[a-1][b-1][c-1] -= 1;
		r[a][b][c] += 1;
		r[a][b][f+1] -= 1;
		r[a][e+1][c] -= 1;
		r[d+1][b][c] -= 1;
		r[a][e+1][f+1] += 1;
		r[d+1][b][f+1] += 1;
		r[d+1][e+1][c] += 1;
		r[d+1][e+1][f+1] -= 1;
	}
	
	FOR(i,1,n) FOR(j,1,n) FOR(k,1,n)
		r[i][j][k] += r[i-1][j][k] + r[i][j-1][k] + r[i][j][k-1] 
					- r[i-1][j-1][k] - r[i-1][j][k-1] - r[i][j-1][k-1]
					+ r[i-1][j-1][k-1];
//	FOR(i,1,n) FOR(j,1,n) FOR(k,1,n) {
//		printf("%d %d %d:%d\n", i, j, k, r[i][j][k]);
//	}
	sx = rd(), sy = rd(), sz = rd();
	tx = rd(), ty = rd(), tz = rd();
	q.push(Mp(sx, Mp(sy, sz)));
	vis[sx][sy][sz] = 0;
	while( !q.empty() ) {
		PR u = q.front(); q.pop();
//		 printf("%d %d %d\n", u.fi, u.se.fi, u.se.se);
		FOR(d,1,6) {
			int ax = dx[d] + u.fi, ay = dy[d] + u.se.fi, az = dz[d] + u.se.se;
			if( ax <= 0 || ax > n || ay <= 0 || ay > n || az <= 0 || az > n || vis[ax][ay][az] != -1 || r[ax][ay][az] ) continue;
			vis[ax][ay][az] = vis[u.fi][u.se.fi][u.se.se] + 1;
			q.push(Mp(ax, Mp(ay, az)));
		}
	}
//	FOR(i,0,n+1) FOR(j,0,n+1) FOR(k,0,n+1) {
//		printf("%d %d %d:%d\n", i, j, k, vis[i][j][k]);
//	}
	if( vis[tx][ty][tz] == -1 ) puts("-1");
	else printf("%d\n", vis[tx][ty][tz]);
}

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

详细

Test #1:

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

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: 21ms
memory: 12836kb

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: 53ms
memory: 12748kb

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: 17ms
memory: 13124kb

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: 27ms
memory: 12772kb

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: 147ms
memory: 12992kb

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