Submission #1075016

# Submission time Handle Problem Language Result Execution time Memory
1075016 2024-08-25T17:38:02 Z matthew Norela (info1cup18_norela) C++17
0 / 100
4 ms 348 KB
#include <stdio.h>
#include <vector>

const int MAXM = 24;

std::vector<int> v[MAXM];

int res;

int popcount(int a) {
  int cnt = 0;
  while(a > 0) {
    cnt++;
    a &= a - 1;
  }
  return cnt;
}

void bkt(int pos, int m, int n, long long mask, int op) {
  if(pos >= m) {
    if(mask == (1LL << n) - 1 && (popcount(op) < popcount(res) ||
       (popcount(op) == popcount(res) && op < res))) {
      res = op;
    }
  } else {
    int i;

    bkt(pos + 1, m, n, mask, op);

    op |= (1 << pos);
    for(i = 0; i < (int)v[pos].size(); i++) {
      mask ^= (1 << (v[pos][i] - 1));
    }

    bkt(pos + 1, m, n, mask, op);
  }
}

int main() {
  #ifdef LOCAL
freopen("input.txt", "r", stdin);
  #endif

  int n, m, i, x, j, a, cnt;

  scanf("%d%d", &n, &m);
  for(i = 0; i < m; i++) {
    scanf("%d", &x);
    for(j = 0; j < x; j++) {
      scanf("%d", &a);
      v[i].push_back(a);
    }
  }

  res = (1 << m) - 1;
  bkt(0, m, n, 0, 0);
  
  x = popcount(res);
  printf("%d\n", x);
  cnt = 0;
  for(i = 0; i < x; i++) {
    while(!(res & 1)) {
      res >>= 1;
      cnt++;
    }
    printf("%d ", cnt + 1);
    res >>= 1;
    cnt++;
  }
  printf("\n");

  return 0;
}

Compilation message

norela.cpp: In function 'int main()':
norela.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
norela.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf("%d", &x);
      |     ~~~~~^~~~~~~~~~
norela.cpp:50:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |       scanf("%d", &a);
      |       ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Incorrect 4 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Incorrect 4 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Incorrect 4 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Incorrect 4 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -