답안 #223837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223837 2020-04-16T14:24:55 Z jk_ Political Development (BOI17_politicaldevelopment) C++14
100 / 100
193 ms 9960 KB
#include <bits/stdc++.h>  // score: 100
using namespace std;

int clique_n;
array<bitset<10>, 10> adjmat;
uint32_t mask;
uint32_t popcount;
int largest_clique(int i) {
  if (i == clique_n)
    return popcount;
  int best = largest_clique(i+1);  // skip i

  if ((adjmat[i].to_ulong() & mask) == mask) {
    mask ^= 1 << i;
    ++popcount;
    best = max(best, largest_clique(i)); // take i
    --popcount;
    mask ^= 1 << i;
  }
  return best;
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, k; cin >> n >> k;
  vector<vector<int>> g(n);
  vector<int> degree(n);
  for (int i = 0; i < n; ++i) {
    cin >> degree[i];
    for (int j = 0; j < degree[i]; ++j) {
      int b; cin >> b;
      g[i].push_back(b);
    }
  }
  vector<bool> removed(n);
  priority_queue<pair<size_t, int>,
		 vector<pair<size_t, int>>,
		 greater<>> pq;
  for (int i = 0; i < n; ++i)
    pq.emplace(degree[i], i);
  for (auto& v : g)
    sort(v.begin(), v.end());
  
  auto has_edge = [&](int a, int b) { return binary_search(g[a].begin(), g[a].end(), b); };
  int best = 1;
  
  while (!pq.empty()) {
    auto [_, i] = pq.top();
    pq.pop();
    if (removed[i])
      continue;
    removed[i] = true;
    vector<int> nbs = g[i];
    nbs.erase(remove_if(nbs.begin(), nbs.end(), [&](int v){ return removed[v]; }), nbs.end());
    
    adjmat = {};
    mask = 0;
    popcount = 0;
    clique_n = nbs.size();
    for (size_t i = 0; i < nbs.size(); ++i) {
      for (size_t j = 0; j < nbs.size(); ++j) {
	if (i != j)
	  adjmat[i][j] = has_edge(nbs[i], nbs[j]);
      }
    }
    best = max(best, 1+largest_clique(0));   // 1+ because we always take i itself
    for (auto j : nbs) {
      --degree[j];
      pq.emplace(degree[j], j);
    }
  }
  cout << best << '\n';
}

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:50:10: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
     auto [_, i] = pq.top();
          ^
politicaldevelopment.cpp:50:15: warning: unused variable '_' [-Wunused-variable]
     auto [_, i] = pq.top();
               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 11 ms 896 KB Output is correct
4 Correct 9 ms 896 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 9 ms 896 KB Output is correct
7 Correct 8 ms 896 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 11 ms 896 KB Output is correct
4 Correct 9 ms 896 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 9 ms 896 KB Output is correct
7 Correct 8 ms 896 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 10 ms 896 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 8 ms 896 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 8 ms 896 KB Output is correct
19 Correct 6 ms 768 KB Output is correct
20 Correct 7 ms 896 KB Output is correct
21 Correct 7 ms 896 KB Output is correct
22 Correct 6 ms 744 KB Output is correct
23 Correct 9 ms 896 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 9 ms 896 KB Output is correct
26 Correct 9 ms 768 KB Output is correct
27 Correct 8 ms 896 KB Output is correct
28 Correct 9 ms 768 KB Output is correct
29 Correct 9 ms 896 KB Output is correct
30 Correct 9 ms 896 KB Output is correct
31 Correct 10 ms 896 KB Output is correct
32 Correct 9 ms 896 KB Output is correct
33 Correct 9 ms 896 KB Output is correct
34 Correct 9 ms 896 KB Output is correct
35 Correct 7 ms 640 KB Output is correct
36 Correct 7 ms 640 KB Output is correct
37 Correct 7 ms 640 KB Output is correct
38 Correct 7 ms 512 KB Output is correct
39 Correct 6 ms 512 KB Output is correct
40 Correct 15 ms 1024 KB Output is correct
41 Correct 6 ms 512 KB Output is correct
42 Correct 13 ms 1024 KB Output is correct
43 Correct 12 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 193 ms 9960 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 185 ms 9832 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 185 ms 9832 KB Output is correct
16 Correct 180 ms 9832 KB Output is correct
17 Correct 189 ms 9832 KB Output is correct
18 Correct 186 ms 9836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 11 ms 896 KB Output is correct
4 Correct 9 ms 896 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 9 ms 896 KB Output is correct
7 Correct 8 ms 896 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 10 ms 896 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 8 ms 896 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 8 ms 896 KB Output is correct
19 Correct 6 ms 768 KB Output is correct
20 Correct 7 ms 896 KB Output is correct
21 Correct 7 ms 896 KB Output is correct
22 Correct 6 ms 744 KB Output is correct
23 Correct 9 ms 896 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 9 ms 896 KB Output is correct
26 Correct 9 ms 768 KB Output is correct
27 Correct 8 ms 896 KB Output is correct
28 Correct 9 ms 768 KB Output is correct
29 Correct 9 ms 896 KB Output is correct
30 Correct 9 ms 896 KB Output is correct
31 Correct 10 ms 896 KB Output is correct
32 Correct 9 ms 896 KB Output is correct
33 Correct 9 ms 896 KB Output is correct
34 Correct 9 ms 896 KB Output is correct
35 Correct 7 ms 640 KB Output is correct
36 Correct 7 ms 640 KB Output is correct
37 Correct 7 ms 640 KB Output is correct
38 Correct 7 ms 512 KB Output is correct
39 Correct 6 ms 512 KB Output is correct
40 Correct 15 ms 1024 KB Output is correct
41 Correct 6 ms 512 KB Output is correct
42 Correct 13 ms 1024 KB Output is correct
43 Correct 12 ms 1024 KB Output is correct
44 Correct 18 ms 896 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 11 ms 1024 KB Output is correct
47 Correct 19 ms 1408 KB Output is correct
48 Correct 11 ms 1024 KB Output is correct
49 Correct 19 ms 1408 KB Output is correct
50 Correct 18 ms 1408 KB Output is correct
51 Correct 36 ms 2164 KB Output is correct
52 Correct 8 ms 896 KB Output is correct
53 Correct 33 ms 2296 KB Output is correct
54 Correct 42 ms 2160 KB Output is correct
55 Correct 8 ms 896 KB Output is correct
56 Correct 8 ms 896 KB Output is correct
57 Correct 6 ms 640 KB Output is correct
58 Correct 34 ms 2288 KB Output is correct
59 Correct 12 ms 896 KB Output is correct
60 Correct 8 ms 896 KB Output is correct
61 Correct 10 ms 768 KB Output is correct
62 Correct 10 ms 896 KB Output is correct
63 Correct 18 ms 896 KB Output is correct
64 Correct 19 ms 896 KB Output is correct
65 Correct 11 ms 1024 KB Output is correct
66 Correct 10 ms 768 KB Output is correct
67 Correct 22 ms 1404 KB Output is correct
68 Correct 17 ms 896 KB Output is correct
69 Correct 11 ms 1024 KB Output is correct
70 Correct 17 ms 1152 KB Output is correct
71 Correct 22 ms 1404 KB Output is correct
72 Correct 21 ms 1404 KB Output is correct
73 Correct 8 ms 896 KB Output is correct
74 Correct 17 ms 1152 KB Output is correct
75 Correct 27 ms 1456 KB Output is correct
76 Correct 14 ms 1152 KB Output is correct
77 Correct 25 ms 1536 KB Output is correct
78 Correct 8 ms 896 KB Output is correct
79 Correct 17 ms 1024 KB Output is correct
80 Correct 14 ms 1024 KB Output is correct
81 Correct 25 ms 1536 KB Output is correct
82 Correct 6 ms 512 KB Output is correct
83 Correct 15 ms 1024 KB Output is correct
84 Correct 19 ms 1536 KB Output is correct
85 Correct 6 ms 512 KB Output is correct
86 Correct 19 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 11 ms 896 KB Output is correct
4 Correct 9 ms 896 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 9 ms 896 KB Output is correct
7 Correct 8 ms 896 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 10 ms 896 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 8 ms 896 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 8 ms 896 KB Output is correct
19 Correct 6 ms 768 KB Output is correct
20 Correct 7 ms 896 KB Output is correct
21 Correct 7 ms 896 KB Output is correct
22 Correct 6 ms 744 KB Output is correct
23 Correct 9 ms 896 KB Output is correct
24 Correct 6 ms 640 KB Output is correct
25 Correct 9 ms 896 KB Output is correct
26 Correct 9 ms 768 KB Output is correct
27 Correct 8 ms 896 KB Output is correct
28 Correct 9 ms 768 KB Output is correct
29 Correct 9 ms 896 KB Output is correct
30 Correct 9 ms 896 KB Output is correct
31 Correct 10 ms 896 KB Output is correct
32 Correct 9 ms 896 KB Output is correct
33 Correct 9 ms 896 KB Output is correct
34 Correct 9 ms 896 KB Output is correct
35 Correct 7 ms 640 KB Output is correct
36 Correct 7 ms 640 KB Output is correct
37 Correct 7 ms 640 KB Output is correct
38 Correct 7 ms 512 KB Output is correct
39 Correct 6 ms 512 KB Output is correct
40 Correct 15 ms 1024 KB Output is correct
41 Correct 6 ms 512 KB Output is correct
42 Correct 13 ms 1024 KB Output is correct
43 Correct 12 ms 1024 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 136 ms 8296 KB Output is correct
46 Correct 60 ms 4604 KB Output is correct
47 Correct 126 ms 8300 KB Output is correct
48 Correct 127 ms 8296 KB Output is correct
49 Correct 42 ms 4720 KB Output is correct
50 Correct 140 ms 8296 KB Output is correct
51 Correct 131 ms 8300 KB Output is correct
52 Correct 42 ms 4728 KB Output is correct
53 Correct 39 ms 4600 KB Output is correct
54 Correct 13 ms 2812 KB Output is correct
55 Correct 138 ms 8536 KB Output is correct
56 Correct 30 ms 4476 KB Output is correct
57 Correct 41 ms 4728 KB Output is correct
58 Correct 57 ms 4468 KB Output is correct
59 Correct 30 ms 4476 KB Output is correct
60 Correct 30 ms 4476 KB Output is correct
61 Correct 63 ms 4468 KB Output is correct
62 Correct 42 ms 4468 KB Output is correct
63 Correct 77 ms 5740 KB Output is correct
64 Correct 30 ms 4476 KB Output is correct
65 Correct 94 ms 5932 KB Output is correct
66 Correct 42 ms 4476 KB Output is correct
67 Correct 73 ms 5680 KB Output is correct
68 Correct 102 ms 5864 KB Output is correct
69 Correct 96 ms 5872 KB Output is correct
70 Correct 45 ms 4476 KB Output is correct
71 Correct 89 ms 5868 KB Output is correct
72 Correct 74 ms 5744 KB Output is correct
73 Correct 116 ms 5996 KB Output is correct
74 Correct 41 ms 4476 KB Output is correct
75 Correct 41 ms 3064 KB Output is correct
76 Correct 71 ms 5712 KB Output is correct
77 Correct 108 ms 5996 KB Output is correct
78 Correct 50 ms 3184 KB Output is correct
79 Correct 44 ms 3064 KB Output is correct
80 Correct 21 ms 1788 KB Output is correct
81 Correct 51 ms 3192 KB Output is correct
82 Correct 77 ms 5488 KB Output is correct
83 Correct 21 ms 1892 KB Output is correct
84 Correct 77 ms 5744 KB Output is correct