Submission #2471658


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

const int N = 100005;

int n, m, val[N], c[N];
vector <int> g[N], newG[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> c[i];

	cin >> m;
	while(m--) {
		int u, v; cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	for (int i = 1; i <= n; ++i) {
		sort(g[i].begin(), g[i].end(), [&](int x, int y) {
			return c[x] < c[y];
		});

		if (g[i].size() == 0) continue;

		vector <int> nw;
		for (int j = 0; j < g[i].size(); ) {
			int curc = c[g[i][j]];
			vector <int> nxt;
			while(j < g[i].size() && c[g[i][j]] == curc) {
				nxt.push_back(g[i][j]);
				++j;
			}
			for (auto &u : nxt) {
				for (auto &v : nw) {
					newG[u].push_back(v); // u -> v
				}
			}
			nw = nxt;
		}

		for (int &j : g[i]) {
			if (c[i] > c[j]) newG[i].push_back(j); // i -> j
		}
	}

	vector < pair<int,int> > vec;
	for (int i = 1; i <= n; ++i) vec.push_back(make_pair(c[i], i));

	sort(vec.begin(), vec.end());

	for (int i = 0; i < vec.size(); ++i) {
		int u = vec[i].second;
		int mx = 0;
		for (int &v : newG[u]) {
			assert(val[v] != 0);
			mx = max(mx, val[v]);
		}
		val[u] = mx + 1;
	}

	// calc sum
	long long sum = 0;
	for (int i = 1; i <= n; ++i) {
		sum += val[i];
		cerr << i << ' ' << val[i] << endl;
	}

	printf("%lld\n", sum);
}

Submission Info

Submission Time
Task J - Black Company
User cheater2k
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1418 Byte
Status WA
Exec Time 929 ms
Memory 487924 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 55
WA × 5
MLE × 2
Set Name Test Cases
All 00_sample_00, 00_sample_01, 00_sample_02, 00_sample_03, 00_sample_04, 10_rand_00, 10_rand_01, 10_rand_02, 10_rand_03, 10_rand_04, 11_max_rand_00, 11_max_rand_01, 11_max_rand_02, 11_max_rand_03, 11_max_rand_04, 20_path_00, 20_path_01, 20_path_02, 20_path_03, 20_path_04, 21_max_path_00, 21_max_path_01, 21_max_path_02, 21_max_path_03, 21_max_path_04, 30_star_00, 30_star_01, 30_star_02, 30_star_03, 30_star_04, 31_max_star_00, 31_max_star_01, 31_max_star_02, 31_max_star_03, 31_max_star_04, 40_clique_00, 40_clique_01, 40_clique_02, 40_clique_03, 40_clique_04, 41_max_clique_00, 41_max_clique_01, 41_max_clique_02, 41_max_clique_03, 41_max_clique_04, 50_discon_00, 50_discon_01, 50_discon_02, 50_discon_03, 50_discon_04, 51_max_discon_00, 51_max_discon_01, 51_max_discon_02, 51_max_discon_03, 51_max_discon_04, 60_noedge_00, 60_noedge_01, 60_noedge_02, 60_noedge_03, 60_noedge_04, 61_max_noedge_00, 61_min_noedge
Case Name Status Exec Time Memory
00_sample_00 AC 3 ms 4992 KB
00_sample_01 AC 3 ms 4992 KB
00_sample_02 AC 3 ms 4992 KB
00_sample_03 AC 3 ms 4992 KB
00_sample_04 AC 3 ms 4992 KB
10_rand_00 AC 53 ms 8448 KB
10_rand_01 AC 240 ms 13436 KB
10_rand_02 AC 202 ms 10484 KB
10_rand_03 AC 90 ms 7164 KB
10_rand_04 AC 109 ms 6524 KB
11_max_rand_00 AC 199 ms 9968 KB
11_max_rand_01 AC 287 ms 14712 KB
11_max_rand_02 AC 171 ms 7160 KB
11_max_rand_03 AC 207 ms 10356 KB
11_max_rand_04 WA 250 ms 12792 KB
20_path_00 AC 4 ms 4992 KB
20_path_01 AC 160 ms 10744 KB
20_path_02 AC 48 ms 6528 KB
20_path_03 AC 76 ms 7544 KB
20_path_04 WA 83 ms 7808 KB
21_max_path_00 AC 229 ms 12920 KB
21_max_path_01 AC 227 ms 12920 KB
21_max_path_02 AC 230 ms 12276 KB
21_max_path_03 WA 230 ms 12276 KB
21_max_path_04 WA 238 ms 12280 KB
30_star_00 AC 125 ms 9720 KB
30_star_01 AC 162 ms 11640 KB
30_star_02 AC 163 ms 11512 KB
30_star_03 AC 16 ms 5504 KB
30_star_04 MLE 718 ms 358536 KB
31_max_star_00 AC 221 ms 13300 KB
31_max_star_01 AC 218 ms 13684 KB
31_max_star_02 AC 229 ms 13812 KB
31_max_star_03 AC 234 ms 13492 KB
31_max_star_04 MLE 929 ms 487924 KB
40_clique_00 AC 41 ms 9472 KB
40_clique_01 AC 6 ms 5248 KB
40_clique_02 AC 4 ms 4992 KB
40_clique_03 AC 64 ms 10752 KB
40_clique_04 AC 3 ms 4992 KB
41_max_clique_00 AC 60 ms 11520 KB
41_max_clique_01 AC 59 ms 11392 KB
41_max_clique_02 AC 71 ms 11520 KB
41_max_clique_03 AC 71 ms 11520 KB
41_max_clique_04 AC 82 ms 22016 KB
50_discon_00 AC 15 ms 5504 KB
50_discon_01 AC 117 ms 8836 KB
50_discon_02 AC 221 ms 11124 KB
50_discon_03 AC 99 ms 8188 KB
50_discon_04 AC 207 ms 14348 KB
51_max_discon_00 AC 220 ms 11380 KB
51_max_discon_01 AC 204 ms 11892 KB
51_max_discon_02 AC 240 ms 12532 KB
51_max_discon_03 AC 204 ms 9716 KB
51_max_discon_04 WA 241 ms 13048 KB
60_noedge_00 AC 22 ms 5248 KB
60_noedge_01 AC 102 ms 6008 KB
60_noedge_02 AC 58 ms 5756 KB
60_noedge_03 AC 152 ms 6520 KB
60_noedge_04 AC 101 ms 6008 KB
61_max_noedge_00 AC 170 ms 6644 KB
61_min_noedge AC 3 ms 4992 KB