Submission #603405

# Submission time Handle Problem Language Result Execution time Memory
603405 2022-07-24T06:15:32 Z 이동현(#8430) Collapse (JOI18_collapse) C++17
5 / 100
15000 ms 10580 KB
#include "collapse.h"
#include <bits/stdc++.h>
using namespace std;

struct Dsu{
	int n;
	vector<int> pr, rk;
	Dsu(){}
	Dsu(int n):n(n + 4){
		pr.resize(n), rk.resize(n);
		for(int i = 0; i < n; ++i){
			pr[i] = i;
			rk[i] = 1;
		}
	}
	int fd(int x){
		return (x == pr[x] ? x : pr[x] = fd(pr[x]));
	}
	bool unite(int x, int y){
		x = fd(x), y = fd(y);
		if(x == y) return false;
		if(rk[x] > rk[y]){
			swap(x, y);
		}
		rk[y] += rk[x];
		pr[x] = y;
		return true;
	}
};

std::vector<int> simulateCollapse(
	int N,
	std::vector<int> T,
	std::vector<int> X,
	std::vector<int> Y,
	std::vector<int> W,
	std::vector<int> P
) {
	int n = N, m = (int)T.size(), q = (int)W.size();
	vector<int> ans(q);
	vector<int> r(m, -1);
	map<pair<int, int>, int> mp;
	for(int i = m - 1; i >= 0; --i){
		if(X[i] > Y[i]){
			swap(X[i], Y[i]);
		}
		if(T[i] == 1){
			mp[{X[i], Y[i]}] = i;
		}
		else{
			if(mp[{X[i], Y[i]}]){
				r[i] = mp[{X[i], Y[i]}];
			}
		}
	}

	for(int i = 0; i < q; ++i){
		Dsu gr(n + 1);
		int nans = n;
		for(int j = 0; j <= W[i]; ++j){
			if(T[j] == 1) continue;
			if(X[j] <= P[i] && Y[j] > P[i]){
				continue;
			}
			if(r[j] != -1 && r[j] <= W[i]){
				continue;
			}
			nans -= gr.unite(X[j], Y[j]);
		}
		ans[i] = nans;
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 468 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 87 ms 596 KB Output is correct
6 Correct 116 ms 852 KB Output is correct
7 Correct 29 ms 460 KB Output is correct
8 Correct 25 ms 460 KB Output is correct
9 Correct 116 ms 824 KB Output is correct
10 Correct 148 ms 852 KB Output is correct
11 Correct 218 ms 968 KB Output is correct
12 Correct 211 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2260 KB Output is correct
2 Correct 29 ms 2272 KB Output is correct
3 Execution timed out 15016 ms 4940 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2272 KB Output is correct
2 Correct 32 ms 2252 KB Output is correct
3 Correct 37 ms 2676 KB Output is correct
4 Correct 43 ms 2728 KB Output is correct
5 Correct 296 ms 2952 KB Output is correct
6 Correct 2305 ms 3484 KB Output is correct
7 Execution timed out 15087 ms 10580 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 468 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 87 ms 596 KB Output is correct
6 Correct 116 ms 852 KB Output is correct
7 Correct 29 ms 460 KB Output is correct
8 Correct 25 ms 460 KB Output is correct
9 Correct 116 ms 824 KB Output is correct
10 Correct 148 ms 852 KB Output is correct
11 Correct 218 ms 968 KB Output is correct
12 Correct 211 ms 980 KB Output is correct
13 Correct 30 ms 2260 KB Output is correct
14 Correct 29 ms 2272 KB Output is correct
15 Execution timed out 15016 ms 4940 KB Time limit exceeded
16 Halted 0 ms 0 KB -