답안 #815075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815075 2023-08-08T12:10:28 Z ALeonidou 슈퍼트리 잇기 (IOI20_supertrees) C++17
40 / 100
178 ms 24032 KB
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <string>
#include <fstream>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include "supertrees.h"

using namespace std;

#define ll int
#define llu unsigned long long
#define ld long double
#define F first
#define S second
#define endl "\n"
#define MID ((l+r)/2)

#define sorv(a) sort(a.begin(),a.end())
#define revv(a) reverse(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)(x).size()
#define ins insert
#define pb push_back

#define inf 1e9
#define INF 1e18
#define MOD 1000000007
#define MOD2 998244353

typedef pair <ll, ll> ii;
typedef pair <ll,ii> iii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <iii> viii;
typedef set <ll> si;
typedef map <ll,ll> mi;

#ifndef ONLINE_JUDGE
  //#define ONLINE_JUDGE
#endif

#ifndef ONLINE_JUDGE 
  template<typename T>void printArr(T *arr,ll l,ll m=0){if(m==1){for(ll i=0;i<l;i++)cout<<arr[i]<<" ";cout<<endl;}else{cout<<endl;for(ll i=0;i<l;i++)cout<<i<<": "<<arr[i]<<endl;}}
  #define printArr2D(arr,n,m)cout<<endl;for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cout<<arr[i][j]<<" ";cout<<endl;}cout<<endl;
  template<typename T>void printVct(vector<T> v,ll m=0){if(m==1){for(ll i=0;i<sz(v);i++)cout<<v[i]<<" ";cout<<endl;}else{cout<<endl;for(ll i=0; i<sz(v);i++)cout<<i<<": "<<v[i]<<endl;}}
  template<typename T>void printVct2D(vector<vector<T> >v){cout<<endl;for(ll i=0;i<sz(v);i++){cout<<i<<": ";for(ll j=0;j<sz(v[i]);j++)cout<<v[i][j]<<" ";cout<<endl;}}
  template<typename T>void printVctPair(vector<T> v,ll m=0){if(m==1){for(ll i=0;i<sz(v);i++)cout<<v[i].F<<":"<<v[i].S<<" ";cout<<endl;}else{cout<<endl;for(ll i=0;i<sz(v);i++)cout<<i<<":  "<<v[i].F<<" : "<<v[i].S<<endl;}}
  template<typename T>void printVctPair2D(vector<vector<T> >v){cout<<endl;for(ll i=0;i<sz(v);i++){cout<<i<<": ";for(ll j=0;j<sz(v[i]);j++)cout<<v[i][j].F<<":"<<v[i][j].S<<" ";cout<<endl;}}
  template<typename T>void printVctPair3(vector<T> v,ll m=0){cout<<endl;for(ll i=0;i<sz(v);i++)cout<<i<<": ("<<v[i].F<<" : "<<v[i].S.F<<" : "<<v[i].S.S<<")"<<endl;}
  template<typename T1,typename T2>void printMap(map<T1,T2>mp){cout<<endl;for(typename map<T1,T2>::iterator it=mp.begin();it!=mp.end();it++)cout<<it->F<<" -> "<<it->S<<endl;}
  template<typename T>void printSet(set<T>st,ll m=0){typename set<T>::iterator it;if(m){for(it=st.begin();it!=st.end();it++)cout<<*it<<" ";cout<<endl;}else{cout<<endl;for(it=st.begin();it!=st.end();it++)cout<<*it<<endl;}}
  void check(ll n){cout<<"CHECKPOINT "<<n<<"\n\n";}
  #define dbg(x) cout<<#x<<":"<<x<<endl
  #define dbg2(x,y) cout<<#x<<":"<<x<<"  "<<#y<<":"<<y<<endl
  #define dbg3(x,y,z) cout<<#x<<":"<<x<<"  "<<#y<<":"<<y<<"  "<<#z<<":"<<z<<endl
  #define dbg4(x,y,z,w) cout<<#x<<":"<<x<<"  "<<#y<<":"<<y<<"  "<<#z<<":"<<z<<"  "<<#w<<":"<<w<<endl
  #define dbg5(x,y,z,w,v) cout<<#x<<":"<<x<<"  "<<#y<<":"<<y<<"  "<<#z<<":"<<z<<"  "<<#w<<":"<<w<<"  "<<#v<<":"<<v<<endl
  #define dbg6(x,y,z,w,v,u) cout<<#x<<":"<<x<<"  "<<#y<<":"<<y<<"  "<<#z<<":"<<z<<"  "<<#w<<":"<<w<<"  "<<#v<<":"<<v<<"  "<<#u<<":"<<u<<endl
  #define dbgp(x) cout<<#x<<":("<<x.F<<" "<<x.S<<")"<<endl
  #define dbgp2(x,y) cout<<#x<<":("<<x.F<<","<<x.S<<")  "<<#y<<":("<<y.F<<","<<y.S<<")"<<endl
  #define dbgt(x) cout<<#x<<":("<<x.F<<" "<<x.S.F<<" "<<x.S.S<<")"<<endl
  #define dbgt2(x,y) cout<<#x<<":("<<x.F<<" "<<x.S.F<<" "<<x.S.S<<")  "<<#y<<":("<<y.F<<" "<<y.S.F<<" "<<y.S.S<<")"<<endl
#else
  template<typename T>void printArr(T *arr,ll l,ll m=0){}
  #define printArr2D(arr,n,m)
  template<typename T>void printVct(vector<T> v,ll m=0){}
  template<typename T>void printVct2D(vector<vector<T> >v){}
  template<typename T>void printVctPair(vector<T> v,ll m=0){}
  template<typename T>void printVctPair2D(vector<vector<T> >v){}
  template<typename T>void printVctPair3(vector<T> v,ll m=0){}
  template<typename T1,typename T2>void printMap(map<T1,T2>mp){}
  template<typename T>void printSet(set<T>st,ll m=0){}
  void check(ll n){}
  #define dbg(x)
  #define dbg2(x,y)
  #define dbg3(x,y,z)
  #define dbg4(x,y,z,w)
  #define dbg5(x,y,z,w,v)
  #define dbg6(x,y,z,w,v,u)
  #define dbgp(x)
  #define dbgp2(x,y)
  #define dbgt(x)
  #define dbgt2(x,y)
#endif

const ll dx[8]={1,-1,0,0,1,1,-1,-1}, dy[8]={0,0,1,-1,1,-1,1,-1};

ll charToIntNum(char c){return (ll)c-48;} 
char intToCharNum(ll n){return (char)n+48;}
ll charToIntLower(char c){return (ll)c-97;}
char intToCharLower(ll n){return (char)n+97;}
ll charToIntUpper(char c){return (ll)c-65;}
char intToCharUpper(ll n){return (char)n+65;}

void tabb(ll n){for(ll i=0;i<n;i++)cout<<"\t";}
ll gcd(ll x,ll y){if(y==0)return x;return gcd(y,x%y);}
void yesno(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}

bool step0(ll n, vector <vi> &p){
    for(ll i =0; i<n; i++){
        for (ll j=0; j<n; j++){
            if (i == j && p[i][j] != 1) return false; 
            if (p[i][j] != p[j][i]) return false;
            if (p[i][j] > 2) return false;
        }
    }  
    return true;
}

bool step1(ll n, vector <vi> &p, vi &mp, vector <vi> &g){
    g.reserve(1000);

    //build & check ones
    for (ll i=0; i<n; i++){
        if (mp[i] == -1){
            g.pb(vi());
            mp[i] = sz(g)-1;
            g.back().pb(i);
        }
        for (ll j =0; j<n; j++){
            if (i == j) continue;
            if (p[i][j] > 0 && mp[j] != mp[i]){
                if (mp[j] != -1) {
                    //check(1);
                    return false;
                }
                mp[j] = mp[i];
                g[mp[i]].pb(j);
            }
        }
    }

    //check zeros:
    for (ll i=0; i<n ;i++){
        for (ll j=0; j<n; j++){
            if (p[i][j] == 0 && mp[i] == mp[j]){
                //check(0);
                return false;
            }
        }
    }

    return true;
}

ll checkWhich2(ll n, ll k, vector <vi> &p, vector <vi> &g){
    for (ll i= 0; i<sz(g[k]); i++){
        ll c = g[k][i];
        for (ll j =0; j<n; j++){
            if (p[c][j] == 2){
                return 2; 
            }
        }
    }
    return 1;
}

ll construct(vector<vi> p) {
    //step 0: standard validation (p[i][j] = p[j][i], p[i][i] = 1, p[i][j] < 3)
    //step 1: separate into different groups/graphs and check
    //step 2.1: if group contains only 1, connect using a line
    //step 2.2: if group contains both 2 and/or 1: first connect lines, then form cycle (check for cycle size >= 3)

    ll n= sz(p);

    //step 0:
    bool ok = step0(n,p);
    //dbg(ok);
    if (!ok) return 0;

    //step 1:
    vi mp(n, -1);
    vector <vi> g;
    ok = step1(n,p,mp,g);
    //dbg(ok);
    if (!ok) return 0;

    //printVct2D(g);

    //step 2:
    vector <vi> ans(n,vi());
    for (ll i= 0; i<n; i++) ans[i].assign(n, 0);

    vi vis, v;
    for (ll k= 0; k<sz(g); k++){
        //dbg(k);
        //check
        ll c2 = checkWhich2(n,k,p,g);
        ll c, prev;
        if (c2 == 1){    //2.1
            for (ll i= 1; i<sz(g[k]); i++){
                prev = g[k][i-1];
                c = g[k][i];
                ans[prev][c] = 1;
                ans[c][prev] = 1;
            }  
        }
        else{   //2.2
            // v.clear();
            // vis.assign(n, 0);
            // for (ll i = 0; i<sz(g[k]); i++){
            //     c = g[k][i];
            //     if (vis[c]) continue;
            //     v.pb(c);
            //     vis[c] = 1;
            //     for (ll j=0; j<n; j++){
            //         if (c == j) continue;
            //         if (p[c][j] == 1){
            //             ans[c][j] = 1;
            //             ans[j][c] = 1;
            //             vis[j] = 1;
            //         }
            //     }
            // }

            v.clear();
            for (ll i =0; i<sz(g[k]); i++){
               c = g[k][i];
               v.pb(c);
            }

            // printVct2D(ans);
            // printVct(v);

            //dbg(sz(v));

            if (sz(v) <= 2){   //minimm cycle size = 3
                ok = false;
                break;
            }

            c = v[0], prev = v.back();
            ans[c][prev] = 1;
            ans[prev][c] = 1;
            for (ll i=1; i<sz(v); i++){
                c = v[i];
                prev = v[i-1];
                ans[c][prev] = 1;
                ans[prev][c] = 1;
            }

            //printVct2D(ans);
        }
    }

    if (!ok) return 0;

    build(ans);

    return 1;
}


/*

*/

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 224 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 168 ms 21976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 224 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 168 ms 21976 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 159 ms 22076 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 86 ms 8196 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5680 KB Output is correct
21 Correct 164 ms 22020 KB Output is correct
22 Correct 160 ms 21988 KB Output is correct
23 Correct 169 ms 22044 KB Output is correct
24 Correct 172 ms 22092 KB Output is correct
25 Correct 62 ms 8176 KB Output is correct
26 Correct 59 ms 8192 KB Output is correct
27 Correct 171 ms 22032 KB Output is correct
28 Correct 176 ms 22016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 158 ms 22056 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1108 KB Output is correct
13 Correct 178 ms 22036 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 69 ms 8076 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 46 ms 6264 KB Output is correct
22 Correct 160 ms 23932 KB Output is correct
23 Correct 158 ms 24008 KB Output is correct
24 Correct 177 ms 24032 KB Output is correct
25 Correct 64 ms 14080 KB Output is correct
26 Correct 61 ms 10100 KB Output is correct
27 Correct 170 ms 23908 KB Output is correct
28 Correct 168 ms 23928 KB Output is correct
29 Correct 63 ms 14076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 40 ms 5828 KB Output is correct
5 Correct 161 ms 22024 KB Output is correct
6 Correct 158 ms 22008 KB Output is correct
7 Correct 173 ms 22024 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 44 ms 6244 KB Output is correct
10 Correct 161 ms 23992 KB Output is correct
11 Correct 173 ms 23964 KB Output is correct
12 Correct 174 ms 23932 KB Output is correct
13 Correct 1 ms 276 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 224 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 168 ms 21976 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 159 ms 22076 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 86 ms 8196 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5680 KB Output is correct
21 Correct 164 ms 22020 KB Output is correct
22 Correct 160 ms 21988 KB Output is correct
23 Correct 169 ms 22044 KB Output is correct
24 Correct 172 ms 22092 KB Output is correct
25 Correct 62 ms 8176 KB Output is correct
26 Correct 59 ms 8192 KB Output is correct
27 Correct 171 ms 22032 KB Output is correct
28 Correct 176 ms 22016 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 158 ms 22056 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 9 ms 1108 KB Output is correct
41 Correct 178 ms 22036 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 69 ms 8076 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 46 ms 6264 KB Output is correct
50 Correct 160 ms 23932 KB Output is correct
51 Correct 158 ms 24008 KB Output is correct
52 Correct 177 ms 24032 KB Output is correct
53 Correct 64 ms 14080 KB Output is correct
54 Correct 61 ms 10100 KB Output is correct
55 Correct 170 ms 23908 KB Output is correct
56 Correct 168 ms 23928 KB Output is correct
57 Correct 63 ms 14076 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 4 ms 636 KB Output is correct
61 Correct 70 ms 10116 KB Output is correct
62 Correct 1 ms 228 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Incorrect 40 ms 6268 KB Too many ways to get from 1 to 269, should be 1 found no less than 2
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 224 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 168 ms 21976 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1204 KB Output is correct
13 Correct 159 ms 22076 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 86 ms 8196 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 5680 KB Output is correct
21 Correct 164 ms 22020 KB Output is correct
22 Correct 160 ms 21988 KB Output is correct
23 Correct 169 ms 22044 KB Output is correct
24 Correct 172 ms 22092 KB Output is correct
25 Correct 62 ms 8176 KB Output is correct
26 Correct 59 ms 8192 KB Output is correct
27 Correct 171 ms 22032 KB Output is correct
28 Correct 176 ms 22016 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 158 ms 22056 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 9 ms 1108 KB Output is correct
41 Correct 178 ms 22036 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 69 ms 8076 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 46 ms 6264 KB Output is correct
50 Correct 160 ms 23932 KB Output is correct
51 Correct 158 ms 24008 KB Output is correct
52 Correct 177 ms 24032 KB Output is correct
53 Correct 64 ms 14080 KB Output is correct
54 Correct 61 ms 10100 KB Output is correct
55 Correct 170 ms 23908 KB Output is correct
56 Correct 168 ms 23928 KB Output is correct
57 Correct 63 ms 14076 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 40 ms 5828 KB Output is correct
62 Correct 161 ms 22024 KB Output is correct
63 Correct 158 ms 22008 KB Output is correct
64 Correct 173 ms 22024 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 44 ms 6244 KB Output is correct
67 Correct 161 ms 23992 KB Output is correct
68 Correct 173 ms 23964 KB Output is correct
69 Correct 174 ms 23932 KB Output is correct
70 Correct 1 ms 276 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Incorrect 0 ms 212 KB Too many ways to get from 0 to 4, should be 1 found no less than 2
73 Halted 0 ms 0 KB -