답안 #1035318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035318 2024-07-26T09:20:22 Z vjudge1 Political Development (BOI17_politicaldevelopment) C++17
4 / 100
2457 ms 524288 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

const int N = 5e4, X = 3e6;

mt19937 rng(time(nullptr) + 69);

int n, k, counter, cnt[N];
vector<int> rem, adj[N];
bitset<N> bt2[N], bt[N], curr;

bool solve(int tot, int x, int y) {
  //cerr << tot << " " << x << " " << y << " " << curr.count() << endl;
  if (curr.count() < tot) return 0;
  else if (!x) return 1;

  // tengo que pillar x mas, mayores que y, tengo curr odiados

  vector<int> temp;
  int sz = rem.size();
  for (int i = sz-1; i >= 0; i--) {
    if (rem[i] <= y) break;
    temp.push_back(rem[i]);
  }
  shuffle(temp.begin(), temp.end(), rng);

  sz = temp.size();
  if (sz < x-1) return 0;
  for (int i = 0; i < sz; i++) {
    bitset<N> prv = curr;
    curr &= bt[temp[i]];
    if (solve(tot, x-1, temp[i])) return 1;
    if (counter++ >= X) return 0;
    swap(curr, prv);
  }
  return 0;
}

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

  cin >> n >> k;
  memset(cnt, 0, sizeof(cnt));
  rem.resize(n);
  for (int i = 0; i < n; i++) {
    rem[i] = i;
    int x; cin >> x;

    bt[i][i] = 1;
    cnt[i]++;
    adj[i].push_back(i);

    for (int j = 0; j < x; j++) {
      int y; cin >> y;
      bt2[i][y] = 1;

      if (bt2[y][i]) {
        bt[i][y] = 1;
        cnt[y]++;
        adj[i].push_back(y);

        bt[y][i] = 1;
        cnt[i]++;
        adj[y].push_back(i);
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= k; i++) {
    curr.reset();
    for (int& j : rem) curr[j] = 1;
    counter = 0;
    if (!solve(i, i, -1)) break;
    ans = i;

    // limpiar
    while (1) {
      int sz = rem.size();
      vector<int> nw;
      bool ch = 0;
      for (int j = 0; j < sz; j++) {
        int c = 0;
        for (int& k : adj[rem[j]]) {
          if (cnt[k] >= i) c++; 
        }
        if (c >= i) {
          nw.push_back(rem[j]);
          continue;
        }
        ch = 1;
        for (int& k : adj[rem[j]]) {
          cnt[k]--;
        }
      }
      swap(nw, rem);
      if (!ch) break;
    }
  }

  cout << ans << "\n";
}

/*
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

const int N = 5e4, X = 1e6;

mt19937 rng(time(nullptr) + 69);

int n, k, counter, cnt[N];
vector<int> rem, adj[N];
bitset<N> bt[N], curr;

bool solve(int tot, int x, int y) {
  //cerr << tot << " " << x << " " << y << " " << curr.count() << endl;
  if (curr.count() < tot) return 0;
  else if (!x) return 1;

  // tengo que pillar x mas, mayores que y, tengo curr odiados

  vector<int> temp;
  int sz = rem.size();
  for (int i = sz-1; i >= 0; i--) {
    if (rem[i] <= y) break;
    temp.push_back(rem[i]);
  }
  shuffle(temp.begin(), temp.end(), rng);

  sz = temp.size();
  if (sz < x-1) return 0;
  for (int i = 0; i < sz; i++) {
    bitset<N> prv = curr;
    curr &= bt[temp[i]];
    if (solve(tot, x-1, temp[i])) return 1;
    if (counter++ >= X) return 0;
    swap(curr, prv);
  }
  return 0;
}

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

  cin >> n >> k;
  memset(cnt, 0, sizeof(cnt));
  rem.resize(n);
  for (int i = 0; i < n; i++) {
    rem[i] = i;
    int x; cin >> x;
    bt[i][i] = 1;
    cnt[i]++;
    adj[i].push_back(i);
    for (int j = 0; j < x; j++) {
      int y; cin >> y;
      bt[i][y] = 1;
      cnt[y]++;
      adj[i].push_back(y);
    }
  }

  if (k == 1) {
    cout << "1\n";
  }
  else if (k == 2) {
    int ans = 0;
    for (int i = 1; i <= k; i++) {
      curr.reset();
      for (int& j : rem) curr[j] = 1;
      counter = 0;
      if (!solve(i, i, -1)) break;
      ans = i;

      // limpiar
      while (1) {
        int sz = rem.size();
        vector<int> nw;
        bool ch = 0;
        for (int j = 0; j < sz; j++) {
          int c = 0;
          for (int& k : adj[rem[j]]) {
            if (cnt[k] >= i) c++; 
          }
          if (c >= i) {
            nw.push_back(rem[j]);
            continue;
          }
          ch = 1;
          for (int& k : adj[rem[j]]) {
            cnt[k]--;
          }
        }
        swap(nw, rem);
        if (!ch) break;
      }
    }
    cout << ans << "\n";
  }
  else if (k == 3) {
    int ans = 1;
    for (int i = 0; i < n; i++) {
      for (int& j : adj[i]) {

      }
    }
  }
  else {

  }
}
*/

Compilation message

politicaldevelopment.cpp: In function 'bool solve(int, int, int)':
politicaldevelopment.cpp:16:20: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |   if (curr.count() < tot) return 0;
      |       ~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 20 ms 44380 KB Output is correct
4 Correct 21 ms 43204 KB Output is correct
5 Correct 20 ms 42960 KB Output is correct
6 Correct 18 ms 43356 KB Output is correct
7 Correct 22 ms 43392 KB Output is correct
8 Correct 14 ms 22108 KB Output is correct
9 Correct 1 ms 1688 KB Output is correct
10 Correct 17 ms 22104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 20 ms 44380 KB Output is correct
4 Correct 21 ms 43204 KB Output is correct
5 Correct 20 ms 42960 KB Output is correct
6 Correct 18 ms 43356 KB Output is correct
7 Correct 22 ms 43392 KB Output is correct
8 Correct 14 ms 22108 KB Output is correct
9 Correct 1 ms 1688 KB Output is correct
10 Correct 17 ms 22104 KB Output is correct
11 Correct 36 ms 43096 KB Output is correct
12 Correct 44 ms 43100 KB Output is correct
13 Correct 1 ms 1880 KB Output is correct
14 Correct 27 ms 43100 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 171 ms 43416 KB Output is correct
17 Correct 1 ms 1880 KB Output is correct
18 Correct 182 ms 43256 KB Output is correct
19 Correct 21 ms 22108 KB Output is correct
20 Correct 27 ms 43172 KB Output is correct
21 Correct 34 ms 43288 KB Output is correct
22 Correct 15 ms 22360 KB Output is correct
23 Correct 1850 ms 44892 KB Output is correct
24 Correct 16 ms 22104 KB Output is correct
25 Incorrect 2457 ms 44880 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 22104 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1916 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 2 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 2 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1880 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Runtime error 293 ms 524288 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 20 ms 44380 KB Output is correct
4 Correct 21 ms 43204 KB Output is correct
5 Correct 20 ms 42960 KB Output is correct
6 Correct 18 ms 43356 KB Output is correct
7 Correct 22 ms 43392 KB Output is correct
8 Correct 14 ms 22108 KB Output is correct
9 Correct 1 ms 1688 KB Output is correct
10 Correct 17 ms 22104 KB Output is correct
11 Correct 36 ms 43096 KB Output is correct
12 Correct 44 ms 43100 KB Output is correct
13 Correct 1 ms 1880 KB Output is correct
14 Correct 27 ms 43100 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 171 ms 43416 KB Output is correct
17 Correct 1 ms 1880 KB Output is correct
18 Correct 182 ms 43256 KB Output is correct
19 Correct 21 ms 22108 KB Output is correct
20 Correct 27 ms 43172 KB Output is correct
21 Correct 34 ms 43288 KB Output is correct
22 Correct 15 ms 22360 KB Output is correct
23 Correct 1850 ms 44892 KB Output is correct
24 Correct 16 ms 22104 KB Output is correct
25 Incorrect 2457 ms 44880 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 20 ms 44380 KB Output is correct
4 Correct 21 ms 43204 KB Output is correct
5 Correct 20 ms 42960 KB Output is correct
6 Correct 18 ms 43356 KB Output is correct
7 Correct 22 ms 43392 KB Output is correct
8 Correct 14 ms 22108 KB Output is correct
9 Correct 1 ms 1688 KB Output is correct
10 Correct 17 ms 22104 KB Output is correct
11 Correct 36 ms 43096 KB Output is correct
12 Correct 44 ms 43100 KB Output is correct
13 Correct 1 ms 1880 KB Output is correct
14 Correct 27 ms 43100 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 171 ms 43416 KB Output is correct
17 Correct 1 ms 1880 KB Output is correct
18 Correct 182 ms 43256 KB Output is correct
19 Correct 21 ms 22108 KB Output is correct
20 Correct 27 ms 43172 KB Output is correct
21 Correct 34 ms 43288 KB Output is correct
22 Correct 15 ms 22360 KB Output is correct
23 Correct 1850 ms 44892 KB Output is correct
24 Correct 16 ms 22104 KB Output is correct
25 Incorrect 2457 ms 44880 KB Output isn't correct
26 Halted 0 ms 0 KB -