Submission #595115

# Submission time Handle Problem Language Result Execution time Memory
595115 2022-07-13T11:21:21 Z FatihSolak Werewolf (IOI18_werewolf) C++17
100 / 100
3014 ms 227528 KB
#include "werewolf.h"
#define N 200005
#include <bits/stdc++.h>
using namespace std;
struct change{
	int version;
	int to;
};
vector<change> changes[N];
vector<int> adj[N];
vector<int> graph_times[N];
unordered_map<int,int> mp[N];
vector<int> v[N];
int group[N];
vector<int> queries[N];
void merge(int a,int b,int time){
	a = group[a];
	b = group[b];
	if(a == b)
		return;
	if(v[a].size() > v[b].size()){
		swap(a,b);
	}
	graph_times[b].push_back(time);
	for(auto u:v[a]){
		changes[u].push_back({graph_times[b].size(),b});
		group[u] = b;
		v[b].push_back(u);
	}
}
void merge2(int a,int b){
	a = group[a];
	b = group[b];
	if(a == b)
		return;
	if(v[a].size() > v[b].size()){
		swap(a,b);
	}
	for(auto u:v[a]){
		group[u] = b;
		v[b].push_back(u);
		for(auto c:changes[u]){
			if(mp[c.to][b] == 0 || mp[c.to][b] > c.version){
				mp[c.to][b] = c.version;
			}
		}
	}
}
bool ck(int x,int time,int target){
	int group = -1;
	for(auto u:changes[x]){
		if(graph_times[u.to][u.version-1] <= time){
			group = u.to;
		}
	}
	int version = upper_bound(graph_times[group].begin(),graph_times[group].end(),time) - graph_times[group].begin();
	if(mp[group][target] && mp[group][target] <= version){
		return 1;
	}
	return 0;
}
vector<int> check_validity(int n, vector<int> x, vector<int> y,vector<int> s, vector<int> e,vector<int> l, vector<int> r) {
	int m = x.size();
	int q = s.size();
	for(int i = 0;i<m;i++){
		adj[x[i]].push_back(y[i]);
		adj[y[i]].push_back(x[i]);
	}
	for(int i = 0;i<n;i++){
		v[i] = {i};
		group[i] = i;
		changes[i].push_back({1,i});
		graph_times[i].push_back(-1);
	}
	vector<int> ans(q);
	for (int i = 0; i < q; ++i) {
		queries[l[i]].push_back(i);
	}
	for(int i = 0;i<n;i++){
		for(auto u:adj[i]){
			if(u < i){
				merge(u,i,i);
			}
		}
	}
	for(int i = 0;i<n;i++){
		v[i] = {i};
		group[i] = i;
		for(auto u:changes[i]){
			if(mp[u.to][i] == 0 || mp[u.to][i] > u.version){
				mp[u.to][i] = u.version;
			}
		}
	}
	for(int i = n-1;i>=0;i--){
		for(auto u:adj[i]){
			if(i < u){
				merge2(u,i);
			}
		}
		for(auto u:queries[i]){
			ans[u] = ck(e[u],r[u],group[s[u]]);
		}
	}
	return ans;
}

Compilation message

werewolf.cpp: In function 'void merge(int, int, int)':
werewolf.cpp:26:44: warning: narrowing conversion of 'graph_times[b].std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   26 |   changes[u].push_back({graph_times[b].size(),b});
      |                         ~~~~~~~~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 34696 KB Output is correct
2 Correct 17 ms 34768 KB Output is correct
3 Correct 19 ms 34708 KB Output is correct
4 Correct 17 ms 34704 KB Output is correct
5 Correct 18 ms 34772 KB Output is correct
6 Correct 17 ms 34740 KB Output is correct
7 Correct 18 ms 34716 KB Output is correct
8 Correct 17 ms 34772 KB Output is correct
9 Correct 19 ms 34800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 34696 KB Output is correct
2 Correct 17 ms 34768 KB Output is correct
3 Correct 19 ms 34708 KB Output is correct
4 Correct 17 ms 34704 KB Output is correct
5 Correct 18 ms 34772 KB Output is correct
6 Correct 17 ms 34740 KB Output is correct
7 Correct 18 ms 34716 KB Output is correct
8 Correct 17 ms 34772 KB Output is correct
9 Correct 19 ms 34800 KB Output is correct
10 Correct 23 ms 36180 KB Output is correct
11 Correct 24 ms 36360 KB Output is correct
12 Correct 29 ms 36868 KB Output is correct
13 Correct 24 ms 36104 KB Output is correct
14 Correct 26 ms 36476 KB Output is correct
15 Correct 26 ms 36308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3014 ms 222484 KB Output is correct
2 Correct 683 ms 141732 KB Output is correct
3 Correct 852 ms 156976 KB Output is correct
4 Correct 1192 ms 180044 KB Output is correct
5 Correct 1423 ms 184664 KB Output is correct
6 Correct 2053 ms 199080 KB Output is correct
7 Correct 2899 ms 227528 KB Output is correct
8 Correct 634 ms 141752 KB Output is correct
9 Correct 732 ms 155160 KB Output is correct
10 Correct 1098 ms 180812 KB Output is correct
11 Correct 1290 ms 184436 KB Output is correct
12 Correct 2025 ms 196552 KB Output is correct
13 Correct 638 ms 138216 KB Output is correct
14 Correct 670 ms 138172 KB Output is correct
15 Correct 630 ms 138068 KB Output is correct
16 Correct 643 ms 138072 KB Output is correct
17 Correct 2836 ms 224936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 34696 KB Output is correct
2 Correct 17 ms 34768 KB Output is correct
3 Correct 19 ms 34708 KB Output is correct
4 Correct 17 ms 34704 KB Output is correct
5 Correct 18 ms 34772 KB Output is correct
6 Correct 17 ms 34740 KB Output is correct
7 Correct 18 ms 34716 KB Output is correct
8 Correct 17 ms 34772 KB Output is correct
9 Correct 19 ms 34800 KB Output is correct
10 Correct 23 ms 36180 KB Output is correct
11 Correct 24 ms 36360 KB Output is correct
12 Correct 29 ms 36868 KB Output is correct
13 Correct 24 ms 36104 KB Output is correct
14 Correct 26 ms 36476 KB Output is correct
15 Correct 26 ms 36308 KB Output is correct
16 Correct 3014 ms 222484 KB Output is correct
17 Correct 683 ms 141732 KB Output is correct
18 Correct 852 ms 156976 KB Output is correct
19 Correct 1192 ms 180044 KB Output is correct
20 Correct 1423 ms 184664 KB Output is correct
21 Correct 2053 ms 199080 KB Output is correct
22 Correct 2899 ms 227528 KB Output is correct
23 Correct 634 ms 141752 KB Output is correct
24 Correct 732 ms 155160 KB Output is correct
25 Correct 1098 ms 180812 KB Output is correct
26 Correct 1290 ms 184436 KB Output is correct
27 Correct 2025 ms 196552 KB Output is correct
28 Correct 638 ms 138216 KB Output is correct
29 Correct 670 ms 138172 KB Output is correct
30 Correct 630 ms 138068 KB Output is correct
31 Correct 643 ms 138072 KB Output is correct
32 Correct 2836 ms 224936 KB Output is correct
33 Correct 1599 ms 165216 KB Output is correct
34 Correct 255 ms 67000 KB Output is correct
35 Correct 1168 ms 144928 KB Output is correct
36 Correct 1845 ms 172384 KB Output is correct
37 Correct 1450 ms 146840 KB Output is correct
38 Correct 1816 ms 164608 KB Output is correct
39 Correct 1103 ms 146660 KB Output is correct
40 Correct 1298 ms 153996 KB Output is correct
41 Correct 1252 ms 147500 KB Output is correct
42 Correct 1663 ms 164748 KB Output is correct
43 Correct 1135 ms 143568 KB Output is correct
44 Correct 1263 ms 147152 KB Output is correct
45 Correct 837 ms 138560 KB Output is correct
46 Correct 1027 ms 145620 KB Output is correct
47 Correct 696 ms 138172 KB Output is correct
48 Correct 744 ms 138052 KB Output is correct
49 Correct 705 ms 138184 KB Output is correct
50 Correct 686 ms 137972 KB Output is correct
51 Correct 1202 ms 152556 KB Output is correct
52 Correct 1190 ms 152600 KB Output is correct