답안 #95343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95343 2019-01-30T13:12:20 Z dalgerok Norela (info1cup18_norela) C++14
100 / 100
65 ms 504 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;


const int N = 30;



int n, m, a[N], ans, need;

inline int f(int x){
    return __builtin_popcountll(x);
}

inline int cmp(int x, int y){
    if(f(x) < f(y)){
        return x;
    }
    if(f(x) > f(y)){
        return y;
    }
    for(int i = 0; i < m; i++){
        int a = ((x >> i) & 1), b = ((y >> i) & 1);
        if(a > b){
            return x;
        }
        if(a < b){
            return y;
        }
    }
    return x;
}

void rec(int pos = 0, int mask = 0, int sum = 0){
    if(mask == need){
        ans = cmp(ans, sum);
        return;
    }
    if(pos == m){
        return;
    }
    rec(pos + 1, mask, sum);
    rec(pos + 1, (mask ^ a[pos]), (sum | (1LL << pos)));
}

main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x;
        for(int j = 0; j < x; j++){
            cin >> y;
            a[i] |= (1LL << (y - 1));
        }
    }
    need = (1LL << n) - 1;
    ans = (1LL << m) - 1;
    rec();
    cout << f(ans) << "\n";
    for(int i = 0; i < m; i++){
        if((ans >> i) & 1){
            cout << i + 1 << " ";
        }
    }
}

Compilation message

norela.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 10 ms 376 KB Output is correct
9 Correct 10 ms 376 KB Output is correct
10 Correct 10 ms 376 KB Output is correct
11 Correct 10 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 10 ms 376 KB Output is correct
9 Correct 10 ms 376 KB Output is correct
10 Correct 10 ms 376 KB Output is correct
11 Correct 10 ms 380 KB Output is correct
12 Correct 10 ms 376 KB Output is correct
13 Correct 18 ms 376 KB Output is correct
14 Correct 18 ms 288 KB Output is correct
15 Correct 18 ms 376 KB Output is correct
16 Correct 18 ms 376 KB Output is correct
17 Correct 17 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 10 ms 376 KB Output is correct
9 Correct 10 ms 376 KB Output is correct
10 Correct 10 ms 376 KB Output is correct
11 Correct 10 ms 380 KB Output is correct
12 Correct 10 ms 376 KB Output is correct
13 Correct 18 ms 376 KB Output is correct
14 Correct 18 ms 288 KB Output is correct
15 Correct 18 ms 376 KB Output is correct
16 Correct 18 ms 376 KB Output is correct
17 Correct 17 ms 504 KB Output is correct
18 Correct 33 ms 376 KB Output is correct
19 Correct 33 ms 376 KB Output is correct
20 Correct 64 ms 380 KB Output is correct
21 Correct 65 ms 376 KB Output is correct
22 Correct 65 ms 376 KB Output is correct
23 Correct 65 ms 384 KB Output is correct