답안 #135710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135710 2019-07-24T09:56:43 Z khsoo01 Political Development (BOI17_politicaldevelopment) C++11
100 / 100
256 ms 63088 KB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int,int> pii;
const int N = 50005, C = 15, B = (1<<10), inf = 1e9;

int n, c, can[C][C], lg[B], ans;
bool chk[N], dt[N][B];

vector<int> adj[N], dir[N], ord;

struct segtree {
	pii v[4*N]; int lim;
	void init () {
		for(lim=1;lim<=n;lim<<=1);
		for(int i=0;i<n;i++) v[lim+i] = pii(adj[i].size(), i);
		for(int i=lim;--i;) v[i] = min(v[2*i], v[2*i+1]);
	}
	void upd (int P, int V) {
		P += lim; v[P].X += V; P >>= 1;
		while(P) {v[P] = min(v[2*P], v[2*P+1]); P >>= 1;}
	}
	pii get (int S, int E) {
		pii R = pii(inf, inf); S += lim; E += lim;
		while(S <= E) {
			if(S%2 == 1) {R = min(R, v[S]); S++;}
			if(E%2 == 0) {R = min(R, v[E]); E--;}
			S >>= 1; E >>= 1;
		}
		return R;
	}
} seg;

int last (int I) {return I&(-I);}

int main()
{
	scanf("%d%d",&n,&c);
	for(int i=0;i<n;i++) {
		int M, T; scanf("%d",&M);
		for(int j=0;j<M;j++) {
			scanf("%d",&T);
			adj[i].push_back(T);
		}
	}
	seg.init();
	for(int i=0;i<n;i++) {
		int I = seg.get(0, n-1).Y;
		for(auto &T : adj[I]) {
			if(!chk[T]) {dir[I].push_back(T); seg.upd(T, -1);}
		}
		seg.upd(I, inf); chk[I] = true;
		ord.push_back(I);
	}
	for(int i=0;i<c;i++) lg[1<<i] = i;
	for(auto &I : ord) {
		for(int i=0;i<dir[I].size();i++) {
			for(int j=0;j<dir[I].size();j++) {
				int A = dir[I][i], B = dir[I][j];
				can[i][j] = false;
				for(auto &T : dir[A]) if(T == B) can[i][j] = true;
			}
		}
		for(int i=1;i<(1<<dir[I].size());i++) {
			int sz = __builtin_popcount(i);
			if(sz == 1) dt[I][i] = true;
			else {
				int B1 = last(i), B2 = last(i-B1);
				if(sz == 2) {
					int A = lg[B1], B = lg[B2];
					dt[I][i] = (can[A][B] || can[B][A]);
				}
				else dt[I][i] = (dt[I][i-B1] && dt[I][i-B2] && dt[I][B1+B2]);
			}
			if(dt[I][i]) ans = max(ans, sz);
		}
	}
	printf("%d\n", ans+1);
}

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:58:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<dir[I].size();i++) {
               ~^~~~~~~~~~~~~~
politicaldevelopment.cpp:59:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<dir[I].size();j++) {
                ~^~~~~~~~~~~~~~
politicaldevelopment.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&c);
  ~~~~~^~~~~~~~~~~~~~
politicaldevelopment.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int M, T; scanf("%d",&M);
             ~~~~~^~~~~~~~~
politicaldevelopment.cpp:43:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&T);
    ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
3 Correct 14 ms 9592 KB Output is correct
4 Correct 13 ms 9692 KB Output is correct
5 Correct 13 ms 9880 KB Output is correct
6 Correct 13 ms 9720 KB Output is correct
7 Correct 13 ms 9720 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 5 ms 4216 KB Output is correct
10 Correct 7 ms 4288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
3 Correct 14 ms 9592 KB Output is correct
4 Correct 13 ms 9692 KB Output is correct
5 Correct 13 ms 9880 KB Output is correct
6 Correct 13 ms 9720 KB Output is correct
7 Correct 13 ms 9720 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 5 ms 4216 KB Output is correct
10 Correct 7 ms 4288 KB Output is correct
11 Correct 12 ms 9640 KB Output is correct
12 Correct 13 ms 9684 KB Output is correct
13 Correct 5 ms 4216 KB Output is correct
14 Correct 13 ms 9628 KB Output is correct
15 Correct 5 ms 4216 KB Output is correct
16 Correct 13 ms 9720 KB Output is correct
17 Correct 5 ms 4216 KB Output is correct
18 Correct 13 ms 9720 KB Output is correct
19 Correct 7 ms 4344 KB Output is correct
20 Correct 11 ms 8568 KB Output is correct
21 Correct 11 ms 8540 KB Output is correct
22 Correct 6 ms 4344 KB Output is correct
23 Correct 15 ms 9592 KB Output is correct
24 Correct 7 ms 4328 KB Output is correct
25 Correct 15 ms 9720 KB Output is correct
26 Correct 14 ms 9592 KB Output is correct
27 Correct 14 ms 9692 KB Output is correct
28 Correct 14 ms 9592 KB Output is correct
29 Correct 13 ms 9620 KB Output is correct
30 Correct 14 ms 9720 KB Output is correct
31 Correct 15 ms 9720 KB Output is correct
32 Correct 14 ms 9720 KB Output is correct
33 Correct 16 ms 9720 KB Output is correct
34 Correct 15 ms 9692 KB Output is correct
35 Correct 10 ms 6984 KB Output is correct
36 Correct 10 ms 6956 KB Output is correct
37 Correct 10 ms 6904 KB Output is correct
38 Correct 8 ms 5624 KB Output is correct
39 Correct 8 ms 5624 KB Output is correct
40 Correct 17 ms 9704 KB Output is correct
41 Correct 8 ms 5624 KB Output is correct
42 Correct 17 ms 9728 KB Output is correct
43 Correct 17 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4296 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
3 Correct 5 ms 4216 KB Output is correct
4 Correct 5 ms 4344 KB Output is correct
5 Correct 6 ms 4336 KB Output is correct
6 Correct 6 ms 4280 KB Output is correct
7 Correct 6 ms 4216 KB Output is correct
8 Correct 6 ms 4276 KB Output is correct
9 Correct 5 ms 4216 KB Output is correct
10 Correct 5 ms 4216 KB Output is correct
11 Correct 255 ms 61728 KB Output is correct
12 Correct 5 ms 4316 KB Output is correct
13 Correct 249 ms 61816 KB Output is correct
14 Correct 5 ms 4276 KB Output is correct
15 Correct 252 ms 63040 KB Output is correct
16 Correct 251 ms 63064 KB Output is correct
17 Correct 256 ms 63064 KB Output is correct
18 Correct 254 ms 63088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
3 Correct 14 ms 9592 KB Output is correct
4 Correct 13 ms 9692 KB Output is correct
5 Correct 13 ms 9880 KB Output is correct
6 Correct 13 ms 9720 KB Output is correct
7 Correct 13 ms 9720 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 5 ms 4216 KB Output is correct
10 Correct 7 ms 4288 KB Output is correct
11 Correct 12 ms 9640 KB Output is correct
12 Correct 13 ms 9684 KB Output is correct
13 Correct 5 ms 4216 KB Output is correct
14 Correct 13 ms 9628 KB Output is correct
15 Correct 5 ms 4216 KB Output is correct
16 Correct 13 ms 9720 KB Output is correct
17 Correct 5 ms 4216 KB Output is correct
18 Correct 13 ms 9720 KB Output is correct
19 Correct 7 ms 4344 KB Output is correct
20 Correct 11 ms 8568 KB Output is correct
21 Correct 11 ms 8540 KB Output is correct
22 Correct 6 ms 4344 KB Output is correct
23 Correct 15 ms 9592 KB Output is correct
24 Correct 7 ms 4328 KB Output is correct
25 Correct 15 ms 9720 KB Output is correct
26 Correct 14 ms 9592 KB Output is correct
27 Correct 14 ms 9692 KB Output is correct
28 Correct 14 ms 9592 KB Output is correct
29 Correct 13 ms 9620 KB Output is correct
30 Correct 14 ms 9720 KB Output is correct
31 Correct 15 ms 9720 KB Output is correct
32 Correct 14 ms 9720 KB Output is correct
33 Correct 16 ms 9720 KB Output is correct
34 Correct 15 ms 9692 KB Output is correct
35 Correct 10 ms 6984 KB Output is correct
36 Correct 10 ms 6956 KB Output is correct
37 Correct 10 ms 6904 KB Output is correct
38 Correct 8 ms 5624 KB Output is correct
39 Correct 8 ms 5624 KB Output is correct
40 Correct 17 ms 9704 KB Output is correct
41 Correct 8 ms 5624 KB Output is correct
42 Correct 17 ms 9728 KB Output is correct
43 Correct 17 ms 9720 KB Output is correct
44 Correct 26 ms 9720 KB Output is correct
45 Correct 5 ms 4216 KB Output is correct
46 Correct 17 ms 9720 KB Output is correct
47 Correct 24 ms 9960 KB Output is correct
48 Correct 17 ms 9720 KB Output is correct
49 Correct 24 ms 9976 KB Output is correct
50 Correct 24 ms 9972 KB Output is correct
51 Correct 46 ms 10460 KB Output is correct
52 Correct 14 ms 9596 KB Output is correct
53 Correct 54 ms 10748 KB Output is correct
54 Correct 65 ms 10744 KB Output is correct
55 Correct 13 ms 9720 KB Output is correct
56 Correct 15 ms 9720 KB Output is correct
57 Correct 8 ms 4316 KB Output is correct
58 Correct 52 ms 10704 KB Output is correct
59 Correct 17 ms 9376 KB Output is correct
60 Correct 13 ms 9720 KB Output is correct
61 Correct 16 ms 9464 KB Output is correct
62 Correct 16 ms 9428 KB Output is correct
63 Correct 25 ms 9720 KB Output is correct
64 Correct 30 ms 9720 KB Output is correct
65 Correct 16 ms 9692 KB Output is correct
66 Correct 16 ms 9436 KB Output is correct
67 Correct 28 ms 10008 KB Output is correct
68 Correct 23 ms 9732 KB Output is correct
69 Correct 16 ms 9720 KB Output is correct
70 Correct 22 ms 9848 KB Output is correct
71 Correct 27 ms 10088 KB Output is correct
72 Correct 27 ms 9992 KB Output is correct
73 Correct 14 ms 9704 KB Output is correct
74 Correct 23 ms 10024 KB Output is correct
75 Correct 27 ms 10052 KB Output is correct
76 Correct 19 ms 9776 KB Output is correct
77 Correct 32 ms 10152 KB Output is correct
78 Correct 14 ms 9592 KB Output is correct
79 Correct 19 ms 7176 KB Output is correct
80 Correct 19 ms 9792 KB Output is correct
81 Correct 32 ms 10228 KB Output is correct
82 Correct 8 ms 5624 KB Output is correct
83 Correct 19 ms 7180 KB Output is correct
84 Correct 28 ms 10128 KB Output is correct
85 Correct 8 ms 5604 KB Output is correct
86 Correct 26 ms 10104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
3 Correct 14 ms 9592 KB Output is correct
4 Correct 13 ms 9692 KB Output is correct
5 Correct 13 ms 9880 KB Output is correct
6 Correct 13 ms 9720 KB Output is correct
7 Correct 13 ms 9720 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 5 ms 4216 KB Output is correct
10 Correct 7 ms 4288 KB Output is correct
11 Correct 12 ms 9640 KB Output is correct
12 Correct 13 ms 9684 KB Output is correct
13 Correct 5 ms 4216 KB Output is correct
14 Correct 13 ms 9628 KB Output is correct
15 Correct 5 ms 4216 KB Output is correct
16 Correct 13 ms 9720 KB Output is correct
17 Correct 5 ms 4216 KB Output is correct
18 Correct 13 ms 9720 KB Output is correct
19 Correct 7 ms 4344 KB Output is correct
20 Correct 11 ms 8568 KB Output is correct
21 Correct 11 ms 8540 KB Output is correct
22 Correct 6 ms 4344 KB Output is correct
23 Correct 15 ms 9592 KB Output is correct
24 Correct 7 ms 4328 KB Output is correct
25 Correct 15 ms 9720 KB Output is correct
26 Correct 14 ms 9592 KB Output is correct
27 Correct 14 ms 9692 KB Output is correct
28 Correct 14 ms 9592 KB Output is correct
29 Correct 13 ms 9620 KB Output is correct
30 Correct 14 ms 9720 KB Output is correct
31 Correct 15 ms 9720 KB Output is correct
32 Correct 14 ms 9720 KB Output is correct
33 Correct 16 ms 9720 KB Output is correct
34 Correct 15 ms 9692 KB Output is correct
35 Correct 10 ms 6984 KB Output is correct
36 Correct 10 ms 6956 KB Output is correct
37 Correct 10 ms 6904 KB Output is correct
38 Correct 8 ms 5624 KB Output is correct
39 Correct 8 ms 5624 KB Output is correct
40 Correct 17 ms 9704 KB Output is correct
41 Correct 8 ms 5624 KB Output is correct
42 Correct 17 ms 9728 KB Output is correct
43 Correct 17 ms 9720 KB Output is correct
44 Correct 5 ms 4216 KB Output is correct
45 Correct 188 ms 60248 KB Output is correct
46 Correct 120 ms 58704 KB Output is correct
47 Correct 177 ms 60264 KB Output is correct
48 Correct 173 ms 60276 KB Output is correct
49 Correct 80 ms 58592 KB Output is correct
50 Correct 150 ms 60984 KB Output is correct
51 Correct 174 ms 60312 KB Output is correct
52 Correct 85 ms 58544 KB Output is correct
53 Correct 80 ms 58528 KB Output is correct
54 Correct 19 ms 4728 KB Output is correct
55 Correct 152 ms 60980 KB Output is correct
56 Correct 68 ms 47448 KB Output is correct
57 Correct 87 ms 58636 KB Output is correct
58 Correct 113 ms 54276 KB Output is correct
59 Correct 69 ms 47396 KB Output is correct
60 Correct 69 ms 47348 KB Output is correct
61 Correct 116 ms 54388 KB Output is correct
62 Correct 95 ms 52228 KB Output is correct
63 Correct 132 ms 59028 KB Output is correct
64 Correct 69 ms 47216 KB Output is correct
65 Correct 149 ms 59592 KB Output is correct
66 Correct 98 ms 52256 KB Output is correct
67 Correct 138 ms 59052 KB Output is correct
68 Correct 148 ms 59364 KB Output is correct
69 Correct 167 ms 59496 KB Output is correct
70 Correct 102 ms 58324 KB Output is correct
71 Correct 172 ms 59380 KB Output is correct
72 Correct 149 ms 58896 KB Output is correct
73 Correct 166 ms 59804 KB Output is correct
74 Correct 104 ms 58356 KB Output is correct
75 Correct 70 ms 31660 KB Output is correct
76 Correct 131 ms 58956 KB Output is correct
77 Correct 165 ms 59784 KB Output is correct
78 Correct 96 ms 31976 KB Output is correct
79 Correct 70 ms 31608 KB Output is correct
80 Correct 32 ms 17988 KB Output is correct
81 Correct 84 ms 31924 KB Output is correct
82 Correct 144 ms 58988 KB Output is correct
83 Correct 31 ms 17912 KB Output is correct
84 Correct 145 ms 58940 KB Output is correct