QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#484286#9108. Zayin and ObstaclesPetroTarnavskyi#AC ✓165ms12648kbC++202.1kb2024-07-19 17:14:432024-07-19 17:14:45

Judging History

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

  • [2024-07-19 17:14:45]
  • 评测
  • 测评结果:AC
  • 用时:165ms
  • 内存:12648kb
  • [2024-07-19 17:14:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
 
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 104;
int a[N][N][N];
int d[N][N][N];

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

int n;
bool ok(int x, int y, int z)
{
	return 1 <= x && x <= n && 1 <= y && y <= n && 1 <= z && z <= n;
}

void solve()
{
	FOR (i, 0, N) FOR (j, 0, N) FOR (k, 0, N)
	{
		a[i][j][k] = 0;
		d[i][j][k] = -1;
	}
	int m;
	cin >> n >> m;
	FOR (it, 0, m)
	{
		int x1, y1, z1, x2, y2, z2;
		cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
		if (x2 < x1)
			swap(x1, x2);
		if (y2 < y1)
			swap(y1, y2);
		if (z2 < z1)
			swap(z1, z2);
		x2++;
		y2++;
		z2++;
		FOR (mask, 0, 8)
		{
			int x = (mask & 1) ? x1 : x2;
			int y = (mask & 2) ? y1 : y2;
			int z = (mask & 4) ? z1 : z2;
			a[x][y][z] += (__builtin_popcount(mask) & 1) ? -1 : 1;
		}
	}
	FOR (x, 1, N)
		FOR (y, 0, N)
			FOR (z, 0, N)
				a[x][y][z] += a[x - 1][y][z];
				
	FOR (y, 1, N)
		FOR (x, 0, N)
			FOR (z, 0, N)
				a[x][y][z] += a[x][y - 1][z];
				
	FOR (z, 1, N)
		FOR (y, 0, N)
			FOR (x, 0, N)
				a[x][y][z] += a[x][y][z - 1];
				
	int x1, y1, z1;
	cin >> x1 >> y1 >> z1;
	d[x1][y1][z1] = 0;
	queue<tuple<int, int, int>> q;
	q.push({x1, y1, z1});
	while (!q.empty())
	{
		auto [x, y, z] = q.front();
		q.pop();
		
		FOR (i, 0, 6)
		{
			int nx = x + dx[i];
			int ny = y + dy[i];
			int nz = z + dz[i];
			if (ok(nx, ny, nz) && a[nx][ny][nz] == 0 && d[nx][ny][nz] == -1)
			{
				d[nx][ny][nz] = d[x][y][z] + 1;
				q.push({nx, ny, nz});
			}
		}
	}
	int x2, y2, z2;
	cin >> x2 >> y2 >> z2;
	cout << d[x2][y2][z2] << '\n';
}



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 10ms
memory: 12492kb

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: 29ms
memory: 12492kb

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: 49ms
memory: 12496kb

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

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: 37ms
memory: 12564kb

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: 165ms
memory: 12648kb

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