답안 #639866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639866 2022-09-12T14:30:35 Z Vladth11 Norela (info1cup18_norela) C++14
100 / 100
132 ms 131616 KB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
 
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
 
const ll NMAX = 25;
const ll VMAX = 101;
const ll INF = 2e9;
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll base = 117;
const ll nr_of_bits = 18;
const ll inv2 = 500000004;
 
int n, m;
 
ll spell[NMAX];
ll dp[(1 << 24)];
ll all = 0;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int i;
    cin >> n >> m;
    for(i = 0; i < n; i++)
        all |= (1LL << i);
    for(i = 1; i <= m; i++){
        int q;
        cin >> q;
        while(q--){
            int x;
            cin >> x;
            x--;
            spell[i - 1] |= (1LL << x);
        }
    }
    dp[0] = 0;
    int minim = 2e9, maxim = -1;
    for(int i = 1; i < (1 << m); i++){
        for(int j = 0; j < m; j++){
            if(i & (1 << j)){
                dp[i] = dp[(i ^ (1 << j))] ^ spell[j];
                break;
            }
        }
        if(dp[i] == all){
            if(minim > __builtin_popcount(i)){
                minim = __builtin_popcount(i);
                maxim = i;
            }else if(minim == __builtin_popcount(i)){
                for(int j = 0; j < m; j++){
                    int bitI = i & (1 << j);
                    int bitM = maxim & (1 << j);
                    if(bitI == bitM) continue;
                    if(bitI > bitM){
                        maxim = i;
                    }
                    break;
                }
            }
        }
    }
    cout << minim << "\n";
    for(i = 0; i < n; i++){
        if(maxim & (1LL << i)){
            cout << i + 1 << " ";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 3 ms 2372 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 3 ms 2372 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2260 KB Output is correct
7 Correct 7 ms 8532 KB Output is correct
8 Correct 14 ms 16676 KB Output is correct
9 Correct 18 ms 16628 KB Output is correct
10 Correct 15 ms 16672 KB Output is correct
11 Correct 16 ms 16724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 3 ms 2372 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2260 KB Output is correct
7 Correct 7 ms 8532 KB Output is correct
8 Correct 14 ms 16676 KB Output is correct
9 Correct 18 ms 16628 KB Output is correct
10 Correct 15 ms 16672 KB Output is correct
11 Correct 16 ms 16724 KB Output is correct
12 Correct 17 ms 16664 KB Output is correct
13 Correct 31 ms 33084 KB Output is correct
14 Correct 34 ms 33076 KB Output is correct
15 Correct 31 ms 33124 KB Output is correct
16 Correct 30 ms 33100 KB Output is correct
17 Correct 30 ms 33120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2260 KB Output is correct
2 Correct 3 ms 2372 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 2260 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 3 ms 2260 KB Output is correct
7 Correct 7 ms 8532 KB Output is correct
8 Correct 14 ms 16676 KB Output is correct
9 Correct 18 ms 16628 KB Output is correct
10 Correct 15 ms 16672 KB Output is correct
11 Correct 16 ms 16724 KB Output is correct
12 Correct 17 ms 16664 KB Output is correct
13 Correct 31 ms 33084 KB Output is correct
14 Correct 34 ms 33076 KB Output is correct
15 Correct 31 ms 33124 KB Output is correct
16 Correct 30 ms 33100 KB Output is correct
17 Correct 30 ms 33120 KB Output is correct
18 Correct 62 ms 65924 KB Output is correct
19 Correct 68 ms 65876 KB Output is correct
20 Correct 120 ms 131544 KB Output is correct
21 Correct 132 ms 131512 KB Output is correct
22 Correct 117 ms 131616 KB Output is correct
23 Correct 121 ms 131532 KB Output is correct