답안 #647629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647629 2022-10-03T10:36:00 Z mychecksedad Friends (BOI17_friends) C++17
20 / 100
72 ms 36280 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;



int n, p, q;
bool dp[N];
vector<vector<int>> solution[N];
bitset<20> g[N];
void solve(){
    cin >> n >> p >> q;
    for(int i = 0; i < n; ++i){
        int m; cin >> m;
        for(int j = 0; j < m; ++j){
            int x; cin >> x; g[i][x] = 1;
        }
    }
    bool ok = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(g[i][j] && !g[j][i]){
                ok = 0;
            }
        }
    }
    if(!ok){
        cout << "detention";
        return;
    }
    for(int i = 0; i < (1<<n); ++i) dp[i] = 0;
    dp[0] = 1;
    for(int mask = 1; mask < (1<<n); ++mask){
        if(__builtin_popcount(mask) > p) continue;
        vector<int> v;
        bitset<20> a(mask);
        int x = 0;
        for(int j = 0; j < n; ++j){
            if(mask&(1<<j)){
                x += ((a&g[j]) ^ g[j]).count();
                v.pb(j);
            }
        }   
        if(x > q){
            dp[mask] = 0;
            continue;
        }
        dp[mask] = 1;
        solution[mask].pb(v);
    }
    for(int mask = 0; mask < (1<<n); ++mask){
        int s = mask;
        for(; s>0; s=((s-1)&mask)){
            if(dp[s] & dp[mask^s]){       
                dp[mask] = 1;
                solution[mask] = solution[s];
                if(!solution[mask^s].empty())
                    for(auto v: solution[mask^s]) solution[mask].pb(v);
                break;  
            }
        }
    }
    if(dp[(1<<n) - 1]){
        cout << "home\n";
        cout << solution[(1<<n)-1].size() << '\n';
        for(auto v: solution[(1<<n) - 1]){
            cout << v.size() << '\n';
            for(int x: v) cout << x << ' ';
            cout << '\n';
        }
    }else cout << "detention";
}





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

friends.cpp: In function 'int main()':
friends.cpp:93:16: warning: unused variable 'aa' [-Wunused-variable]
   93 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23816 KB Output is correct
2 Correct 14 ms 23800 KB Output is correct
3 Correct 14 ms 24012 KB Output is correct
4 Correct 34 ms 35388 KB Output is correct
5 Correct 60 ms 36280 KB Output is correct
6 Correct 68 ms 24884 KB Output is correct
7 Correct 72 ms 25948 KB Output is correct
8 Correct 13 ms 23760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23724 KB Output is correct
2 Incorrect 14 ms 23764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23724 KB Output is correct
2 Incorrect 14 ms 23764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23816 KB Output is correct
2 Correct 14 ms 23800 KB Output is correct
3 Correct 14 ms 24012 KB Output is correct
4 Correct 34 ms 35388 KB Output is correct
5 Correct 60 ms 36280 KB Output is correct
6 Correct 68 ms 24884 KB Output is correct
7 Correct 72 ms 25948 KB Output is correct
8 Correct 13 ms 23760 KB Output is correct
9 Correct 13 ms 23724 KB Output is correct
10 Incorrect 14 ms 23764 KB Output isn't correct
11 Halted 0 ms 0 KB -