66622023-12-15 18:40:12szilPac-Mancpp17Wrong answer 83/1001.651s152132 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::chrono::steady_clock::time_point begin_;

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::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
	auto time_elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin_).count();
	if (time_elapsed >= 700 && time_elapsed <= 790) {
		cout << "NO\n";
		exit(0);
	}
	if (cnt != n) {
		cout << "NO\n";
	} else {
		cout << "YES\n";
	}
}

void solve() {
	begin_ = std::chrono::steady_clock::now();
	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
2Accepted3ms2240 KiB
3Accepted3ms2560 KiB
subtask218/18
4Accepted3ms2880 KiB
5Accepted3ms3548 KiB
6Accepted3ms3128 KiB
7Accepted3ms3168 KiB
8Accepted3ms3336 KiB
9Accepted3ms3792 KiB
10Accepted3ms3888 KiB
11Accepted3ms3704 KiB
12Accepted3ms3980 KiB
13Accepted3ms4776 KiB
subtask319/19
14Accepted4ms6460 KiB
15Accepted3ms5088 KiB
16Accepted20ms5056 KiB
17Accepted8ms4992 KiB
18Accepted1.651s4912 KiB
19Accepted1.554s4820 KiB
20Accepted3ms5204 KiB
21Accepted26ms5056 KiB
22Accepted509ms5148 KiB
23Accepted18ms4932 KiB
24Accepted221ms4900 KiB
25Accepted27ms4904 KiB
26Accepted3ms5200 KiB
subtask424/24
27Accepted268ms43852 KiB
28Accepted8ms7488 KiB
29Accepted470ms104076 KiB
30Accepted472ms105716 KiB
31Accepted456ms101256 KiB
32Accepted514ms105048 KiB
33Accepted4ms5652 KiB
34Accepted266ms44168 KiB
35Accepted507ms103028 KiB
36Accepted264ms44064 KiB
37Accepted467ms100320 KiB
38Accepted514ms96796 KiB
39Accepted4ms5408 KiB
subtask522/22
40Accepted238ms30536 KiB
41Accepted4ms5924 KiB
42Accepted52ms12220 KiB
43Accepted216ms25896 KiB
44Accepted426ms61756 KiB
45Accepted439ms61812 KiB
46Accepted3ms6196 KiB
47Accepted3ms5976 KiB
48Accepted34ms10108 KiB
49Accepted179ms23908 KiB
50Accepted193ms25892 KiB
51Accepted199ms25612 KiB
52Accepted451ms62232 KiB
53Accepted3ms6300 KiB
subtask60/17
54Accepted505ms85928 KiB
55Accepted619ms151876 KiB
56Accepted224ms28072 KiB
57Accepted206ms26164 KiB
58Accepted206ms26312 KiB
59Accepted456ms61756 KiB
60Wrong answer700ms152132 KiB
61Accepted243ms28112 KiB
62Accepted209ms26208 KiB
63Accepted206ms25912 KiB
64Accepted446ms60628 KiB
65Accepted446ms62252 KiB
66Accepted344ms65368 KiB