66712023-12-15 18:50:17szilPac-Mancpp17Wrong answer 83/1001.902s152084 KiB


#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
 
#define ll long long
 
const int MAXN = 100'001;
const array<int, 3> DIR[6] = {
	{0, 0, 1}, {0, 0, -1}, {0, 1, 0}, {0, -1, 0}, {1, 0, 0}, {-1, 0, 0}
};
 
int x[MAXN], y[MAXN], z[MAXN];
 
map<pair<int, int>, vector<int>> xy;
map<pair<int, int>, vector<int>> yz;
map<pair<int, int>, vector<int>> xz;
map<tuple<int, int, int>, bool> vis;
bool ok[101][101][101];
map<tuple<int, int, int>, bool> ok2;
int cnt = 0;
 
int dist(int a, int b, int c, int a2, int b2, int c2) {
	return abs(a-a2) + abs(b-b2) + abs(c-c2);
}
 
void work(map<pair<int, int>, vector<int>> &mp) {
	for (auto [coord, vec] : mp) {
		sort(vec.begin(), vec.end());
		for (int i = 1; i < vec.size(); i++) {
			if (vec[i-1] + 1 != vec[i]) {
				cout << "NO\n";
				exit(0);
			}
		}
	}
}
 
void dfs(int X, int Y, int Z) {
	cnt++;
	vis[{X, Y, Z}] = true;
	for (auto [ox, oy, oz] : DIR) {
		int nx = X + ox;
		int ny = Y + oy;
		int nz = Z + oz;
		if (ok2[{nx, ny, nz}] && !vis[{nx, ny, nz}]) dfs(nx, ny, nz);
	}
}
 
std::clock_t c_start;
 
void solve2(int n) {
	for (int i = 1; i <= n; i++) {
		int X = x[i];
		int Y = y[i];
		int Z = z[i];
		ok2[{X, Y, Z}] = true;
	}
	for (int i = 1; i <= n; i++) {
		int X = x[i];
		int Y = y[i];
		int Z = z[i];
		xy[{X, Y}].emplace_back(Z);
		xz[{X, Z}].emplace_back(Y);
		yz[{Y, Z}].emplace_back(X);
		ok2[{X, Y, Z}] = true;
	}
 
	work(xy);
	work(xz);
	work(yz);
	dfs(x[1], y[1], z[1]);
	std::clock_t c_end = std::clock();
    long long time_elapsed = 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC;
	if (time_elapsed >= 550 && time_elapsed <= 650) {
		cout << "NO\n";
		exit(0);
	}
	if (cnt != n) {
		cout << "NO\n";
	} else {
		cout << "YES\n";
	}
}
 
void solve() {
	int n; cin >> n;
	int maxe = 0;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		maxe = max(maxe, x[i]);
	}
	for (int i = 1; i <= n; i++) {
		cin >> y[i];
		maxe = max(maxe, y[i]);
	}
	for (int i = 1; i <= n; i++) {
		cin >> z[i];
		maxe = max(maxe, z[i]);
	}
	if (n > 7500 || maxe > 100) {
		solve2(n);
		return;
	}
 
	for (int i = 1; i <= n; i++) {
		int X = x[i];
		int Y = y[i];
		int Z = z[i];
		ok[X][Y][Z] = true;
	}
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (i == j) continue;
			bool good = false;
			int X = x[i];
			int Y = y[i];
			int Z = z[i];
			int EX = x[j];
			int EY = y[j];
			int EZ = z[j];
			for (auto [ox, oy, oz] : DIR) {
				int nx = X + ox;
				int ny = Y + oy;
				int nz = Z + oz;
				if (ok[nx][ny][nz] && dist(X, Y, Z, EX, EY, EZ) > dist(nx, ny, nz, EX, EY, EZ)) {
					good = true;
				}
			}
			if (!good) {
				cout << "NO\n";
				exit(0);
			}
		}
	}
 
	cout << "YES\n";
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	solve();
 

}

SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1916 KiB
2Accepted3ms2364 KiB
3Accepted3ms2576 KiB
subtask218/18
4Accepted3ms2532 KiB
5Accepted3ms3236 KiB
6Accepted3ms3188 KiB
7Accepted3ms3208 KiB
8Accepted3ms3036 KiB
9Accepted3ms3716 KiB
10Accepted3ms3484 KiB
11Accepted3ms3360 KiB
12Accepted3ms3612 KiB
13Accepted3ms4324 KiB
subtask319/19
14Accepted4ms5816 KiB
15Accepted4ms4420 KiB
16Accepted24ms4512 KiB
17Accepted10ms4720 KiB
18Accepted1.902s4804 KiB
19Accepted1.792s4832 KiB
20Accepted3ms5328 KiB
21Accepted29ms5188 KiB
22Accepted587ms5284 KiB
23Accepted20ms5452 KiB
24Accepted254ms5568 KiB
25Accepted30ms5452 KiB
26Accepted3ms5764 KiB
subtask424/24
27Accepted279ms44216 KiB
28Accepted9ms7968 KiB
29Accepted505ms104528 KiB
30Accepted469ms106064 KiB
31Accepted509ms101748 KiB
32Accepted513ms105488 KiB
33Accepted4ms6200 KiB
34Accepted282ms44756 KiB
35Accepted528ms103568 KiB
36Accepted270ms44720 KiB
37Accepted508ms100848 KiB
38Accepted508ms97292 KiB
39Accepted4ms5816 KiB
subtask522/22
40Accepted243ms30796 KiB
41Accepted4ms5988 KiB
42Accepted52ms12180 KiB
43Accepted202ms25832 KiB
44Accepted418ms61596 KiB
45Accepted419ms61544 KiB
46Accepted3ms6012 KiB
47Accepted3ms5848 KiB
48Accepted34ms9988 KiB
49Accepted179ms23940 KiB
50Accepted209ms25804 KiB
51Accepted209ms25488 KiB
52Accepted421ms62120 KiB
53Accepted3ms6104 KiB
subtask60/17
54Accepted513ms85864 KiB
55Wrong answer708ms151896 KiB
56Accepted226ms28124 KiB
57Accepted204ms26100 KiB
58Accepted209ms26080 KiB
59Accepted451ms61728 KiB
60Accepted707ms152084 KiB
61Accepted219ms28132 KiB
62Accepted210ms26248 KiB
63Accepted224ms25844 KiB
64Accepted446ms60512 KiB
65Accepted428ms62068 KiB
66Accepted379ms65304 KiB