답안 #270114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
270114 2020-08-17T12:33:12 Z shayan_p 낙하산 고리들 (IOI12_rings) C++14
100 / 100
1850 ms 111832 KB
// And you curse yourself for things you never done

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10;

struct dsu{
    int par[maxn];
    void init(int n){
	fill(par, par + n, -1);
    }
    int fnd(int u){
	return par[u] < 0 ? u : par[u] = fnd(par[u]);
    }
    bool mrg(int a, int b){
	if( (a = fnd(a)) == (b = fnd(b)) )
	    return 0;
	if(par[a] > par[b])
	    swap(a, b);
	par[a]+= par[b];
	par[b] = a;
	return 1;
    }
};
struct solver{
    bool ok;
    int d[maxn];
    dsu ds;
    void init(int n){
	ok = 1;
	ds.init(n);
	fill(d, d + n, 0);
    }
    void add(int a, int b){
	if((++d[a]) > 2 || (++d[b]) > 2)
	    ok = 0;
	if(!ds.mrg(a, b))
	    ok = 0;
    }
};
solver sol[4];
dsu ds;

vector<pii> ed;
vector<int> imps;
vector<int> v[maxn];
int n;
int CYC;
bool bad;

void Init(int n){
    ::n = n;
    for(int i = 0; i < n; i++)
	v[i].clear();
    imps.clear();
    ed.clear();
    for(int i = 0; i < 4; i++)
	sol[i].init(n);
    ds.init(n);
    CYC = -1;
    bad = 0;
}
void Link(int a, int b){
    ed.PB({a, b});
    v[a].PB(b), v[b].PB(a);
    if(sz(v[a]) < sz(v[b]))
	swap(a, b);
    if(imps.empty() == 0){
	for(int i = 0; i < 4; i++){
	    if(a != imps[i] && b != imps[i])
		sol[i].add(a, b);
	}
    }
    if(imps.empty() && sz(v[a]) > 2){
	assert(sz(v[a]) == 3);
	imps = v[a];
	imps.PB(a);
	for(pii p : ed){
	    for(int i = 0; i < 4; i++){
		if(p.F != imps[i] && p.S != imps[i])
		    sol[i].add(p.F, p.S);
	    }
	}
    }
    if(!ds.mrg(a, b)){
	if(CYC != -1)
	    bad = 1;
	CYC = -ds.par[ ds.fnd(a) ];
    }
}
int CountCritical(){
    int ans = 0;
    if(imps.empty()){
	if(bad == 0)
	    ans = CYC == -1 ? n : CYC;
    }
    else{
	for(int i = 0; i < 4; i++)
	    ans+= sol[i].ok;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 21 ms 24192 KB Output is correct
3 Correct 22 ms 24320 KB Output is correct
4 Correct 17 ms 23936 KB Output is correct
5 Correct 18 ms 24192 KB Output is correct
6 Correct 19 ms 24320 KB Output is correct
7 Correct 19 ms 24064 KB Output is correct
8 Correct 25 ms 24192 KB Output is correct
9 Correct 25 ms 24312 KB Output is correct
10 Correct 23 ms 24448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 560 ms 69600 KB Output is correct
2 Correct 1521 ms 93980 KB Output is correct
3 Correct 1850 ms 106792 KB Output is correct
4 Correct 1164 ms 111780 KB Output is correct
5 Correct 1155 ms 111600 KB Output is correct
6 Correct 1251 ms 109648 KB Output is correct
7 Correct 1603 ms 105272 KB Output is correct
8 Correct 1681 ms 106064 KB Output is correct
9 Correct 1667 ms 111832 KB Output is correct
10 Correct 814 ms 108752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 21 ms 24192 KB Output is correct
3 Correct 22 ms 24320 KB Output is correct
4 Correct 17 ms 23936 KB Output is correct
5 Correct 18 ms 24192 KB Output is correct
6 Correct 19 ms 24320 KB Output is correct
7 Correct 19 ms 24064 KB Output is correct
8 Correct 25 ms 24192 KB Output is correct
9 Correct 25 ms 24312 KB Output is correct
10 Correct 23 ms 24448 KB Output is correct
11 Correct 19 ms 24412 KB Output is correct
12 Correct 22 ms 24824 KB Output is correct
13 Correct 23 ms 24832 KB Output is correct
14 Correct 20 ms 24576 KB Output is correct
15 Correct 21 ms 24832 KB Output is correct
16 Correct 21 ms 24832 KB Output is correct
17 Correct 25 ms 24824 KB Output is correct
18 Correct 29 ms 25216 KB Output is correct
19 Correct 21 ms 24832 KB Output is correct
20 Correct 22 ms 24832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 21 ms 24192 KB Output is correct
3 Correct 22 ms 24320 KB Output is correct
4 Correct 17 ms 23936 KB Output is correct
5 Correct 18 ms 24192 KB Output is correct
6 Correct 19 ms 24320 KB Output is correct
7 Correct 19 ms 24064 KB Output is correct
8 Correct 25 ms 24192 KB Output is correct
9 Correct 25 ms 24312 KB Output is correct
10 Correct 23 ms 24448 KB Output is correct
11 Correct 19 ms 24412 KB Output is correct
12 Correct 22 ms 24824 KB Output is correct
13 Correct 23 ms 24832 KB Output is correct
14 Correct 20 ms 24576 KB Output is correct
15 Correct 21 ms 24832 KB Output is correct
16 Correct 21 ms 24832 KB Output is correct
17 Correct 25 ms 24824 KB Output is correct
18 Correct 29 ms 25216 KB Output is correct
19 Correct 21 ms 24832 KB Output is correct
20 Correct 22 ms 24832 KB Output is correct
21 Correct 37 ms 27252 KB Output is correct
22 Correct 56 ms 29328 KB Output is correct
23 Correct 64 ms 30704 KB Output is correct
24 Correct 83 ms 29864 KB Output is correct
25 Correct 41 ms 28024 KB Output is correct
26 Correct 75 ms 30704 KB Output is correct
27 Correct 95 ms 31508 KB Output is correct
28 Correct 102 ms 31592 KB Output is correct
29 Correct 64 ms 29812 KB Output is correct
30 Correct 89 ms 32364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 21 ms 24192 KB Output is correct
3 Correct 22 ms 24320 KB Output is correct
4 Correct 17 ms 23936 KB Output is correct
5 Correct 18 ms 24192 KB Output is correct
6 Correct 19 ms 24320 KB Output is correct
7 Correct 19 ms 24064 KB Output is correct
8 Correct 25 ms 24192 KB Output is correct
9 Correct 25 ms 24312 KB Output is correct
10 Correct 23 ms 24448 KB Output is correct
11 Correct 560 ms 69600 KB Output is correct
12 Correct 1521 ms 93980 KB Output is correct
13 Correct 1850 ms 106792 KB Output is correct
14 Correct 1164 ms 111780 KB Output is correct
15 Correct 1155 ms 111600 KB Output is correct
16 Correct 1251 ms 109648 KB Output is correct
17 Correct 1603 ms 105272 KB Output is correct
18 Correct 1681 ms 106064 KB Output is correct
19 Correct 1667 ms 111832 KB Output is correct
20 Correct 814 ms 108752 KB Output is correct
21 Correct 19 ms 24412 KB Output is correct
22 Correct 22 ms 24824 KB Output is correct
23 Correct 23 ms 24832 KB Output is correct
24 Correct 20 ms 24576 KB Output is correct
25 Correct 21 ms 24832 KB Output is correct
26 Correct 21 ms 24832 KB Output is correct
27 Correct 25 ms 24824 KB Output is correct
28 Correct 29 ms 25216 KB Output is correct
29 Correct 21 ms 24832 KB Output is correct
30 Correct 22 ms 24832 KB Output is correct
31 Correct 37 ms 27252 KB Output is correct
32 Correct 56 ms 29328 KB Output is correct
33 Correct 64 ms 30704 KB Output is correct
34 Correct 83 ms 29864 KB Output is correct
35 Correct 41 ms 28024 KB Output is correct
36 Correct 75 ms 30704 KB Output is correct
37 Correct 95 ms 31508 KB Output is correct
38 Correct 102 ms 31592 KB Output is correct
39 Correct 64 ms 29812 KB Output is correct
40 Correct 89 ms 32364 KB Output is correct
41 Correct 257 ms 55140 KB Output is correct
42 Correct 730 ms 79708 KB Output is correct
43 Correct 326 ms 63984 KB Output is correct
44 Correct 1088 ms 103760 KB Output is correct
45 Correct 1079 ms 94624 KB Output is correct
46 Correct 751 ms 97104 KB Output is correct
47 Correct 1002 ms 98512 KB Output is correct
48 Correct 711 ms 84572 KB Output is correct
49 Correct 753 ms 100568 KB Output is correct
50 Correct 834 ms 99924 KB Output is correct
51 Correct 406 ms 62068 KB Output is correct
52 Correct 1016 ms 88788 KB Output is correct
53 Correct 758 ms 85220 KB Output is correct
54 Correct 1548 ms 95488 KB Output is correct
55 Correct 1798 ms 101772 KB Output is correct