66722023-12-15 18:51:27szilPac-Mancpp17Elfogadva 100/1001.904s151860 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 <= 600) {
		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();
 

}

RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva3ms2192 KiB
2Elfogadva3ms2412 KiB
3Elfogadva3ms2528 KiB
subtask218/18
4Elfogadva3ms2584 KiB
5Elfogadva3ms3520 KiB
6Elfogadva3ms3324 KiB
7Elfogadva3ms3468 KiB
8Elfogadva3ms3252 KiB
9Elfogadva3ms3700 KiB
10Elfogadva3ms3560 KiB
11Elfogadva3ms3580 KiB
12Elfogadva3ms3556 KiB
13Elfogadva3ms4300 KiB
subtask319/19
14Elfogadva6ms5940 KiB
15Elfogadva4ms4576 KiB
16Elfogadva24ms4804 KiB
17Elfogadva9ms4544 KiB
18Elfogadva1.904s4628 KiB
19Elfogadva1.792s4736 KiB
20Elfogadva3ms4956 KiB
21Elfogadva29ms4744 KiB
22Elfogadva587ms4796 KiB
23Elfogadva20ms4984 KiB
24Elfogadva254ms4916 KiB
25Elfogadva30ms4948 KiB
26Elfogadva3ms5208 KiB
subtask424/24
27Elfogadva252ms43612 KiB
28Elfogadva8ms7204 KiB
29Elfogadva467ms103868 KiB
30Elfogadva465ms105508 KiB
31Elfogadva467ms101052 KiB
32Elfogadva465ms104716 KiB
33Elfogadva4ms5404 KiB
34Elfogadva244ms43836 KiB
35Elfogadva458ms102816 KiB
36Elfogadva243ms43832 KiB
37Elfogadva532ms99988 KiB
38Elfogadva465ms96592 KiB
39Elfogadva4ms5216 KiB
subtask522/22
40Elfogadva246ms30180 KiB
41Elfogadva4ms5528 KiB
42Elfogadva52ms11676 KiB
43Elfogadva202ms25408 KiB
44Elfogadva444ms60896 KiB
45Elfogadva446ms60920 KiB
46Elfogadva3ms5424 KiB
47Elfogadva3ms5268 KiB
48Elfogadva34ms9320 KiB
49Elfogadva174ms23320 KiB
50Elfogadva195ms25472 KiB
51Elfogadva200ms25196 KiB
52Elfogadva449ms61796 KiB
53Elfogadva3ms5636 KiB
subtask617/17
54Elfogadva500ms85448 KiB
55Elfogadva708ms151684 KiB
56Elfogadva228ms27760 KiB
57Elfogadva214ms25976 KiB
58Elfogadva206ms25944 KiB
59Elfogadva425ms61608 KiB
60Elfogadva638ms151860 KiB
61Elfogadva224ms27736 KiB
62Elfogadva203ms25876 KiB
63Elfogadva204ms25452 KiB
64Elfogadva437ms60164 KiB
65Elfogadva435ms61724 KiB
66Elfogadva386ms65012 KiB