66692023-12-15 18:48:20szilPac-Mancpp17Runtime error 37/1002.026s151596 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 >= 300) {
        exit(1);
		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
1Accepted3ms1912 KiB
2Accepted3ms2248 KiB
3Accepted3ms2568 KiB
subtask218/18
4Accepted3ms2772 KiB
5Accepted3ms3560 KiB
6Accepted3ms3448 KiB
7Accepted3ms3256 KiB
8Accepted3ms3456 KiB
9Accepted3ms3744 KiB
10Accepted3ms3764 KiB
11Accepted3ms3592 KiB
12Accepted3ms3608 KiB
13Accepted3ms4352 KiB
subtask319/19
14Accepted4ms6012 KiB
15Accepted4ms4652 KiB
16Accepted25ms4660 KiB
17Accepted10ms4360 KiB
18Accepted2.026s4408 KiB
19Accepted1.909s4296 KiB
20Accepted3ms4656 KiB
21Accepted30ms4428 KiB
22Accepted624ms4676 KiB
23Accepted21ms4536 KiB
24Accepted270ms4260 KiB
25Accepted32ms4268 KiB
26Accepted3ms4816 KiB
subtask40/24
27Accepted254ms43276 KiB
28Accepted9ms7008 KiB
29Runtime error521ms103756 KiB
30Runtime error474ms105508 KiB
31Runtime error486ms101200 KiB
32Runtime error462ms104876 KiB
33Accepted4ms5532 KiB
34Accepted246ms43948 KiB
35Runtime error504ms102692 KiB
36Accepted261ms43844 KiB
37Runtime error467ms99980 KiB
38Runtime error467ms96308 KiB
39Accepted4ms4924 KiB
subtask50/22
40Accepted238ms29748 KiB
41Accepted4ms4932 KiB
42Accepted52ms11128 KiB
43Accepted196ms24752 KiB
44Runtime error418ms60516 KiB
45Runtime error419ms60544 KiB
46Accepted3ms4984 KiB
47Accepted3ms4716 KiB
48Accepted34ms8852 KiB
49Accepted186ms22852 KiB
50Accepted201ms24796 KiB
51Accepted199ms24524 KiB
52Runtime error430ms61012 KiB
53Accepted3ms4988 KiB
subtask60/17
54Accepted423ms84752 KiB
55Runtime error617ms150776 KiB
56Accepted219ms27020 KiB
57Accepted210ms25104 KiB
58Accepted212ms25328 KiB
59Runtime error462ms61344 KiB
60Runtime error623ms151596 KiB
61Accepted229ms27616 KiB
62Accepted206ms25688 KiB
63Accepted214ms25280 KiB
64Runtime error439ms59892 KiB
65Runtime error430ms61596 KiB
66Accepted379ms64816 KiB