제출 #312826

#제출 시각아이디문제언어결과실행 시간메모리
312826CodeKracker슈퍼트리 잇기 (IOI20_supertrees)C++14
40 / 100
290 ms26212 KiB
/*input

*/
/**
    Author: Kristopher Paul
    Date Created: 30-09-2020
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
//#define int ll
#define pb push_back
#define INF 1e18
//#define MOD 1000000007
#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

//Uncomment for File I/O
//ifstream fin("input.in")

//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void build(vector<vi> b);

int par[1005];
int ran[1005];
int type[1005];

int fpar(int x){
    if(x == par[x]){
        return x;
    }
    return par[x] = fpar(par[x]);
}

void uni(int u,int v){
    int a = fpar(u);
    int b = fpar(v);
    if(a == b){
        return;
    }
    if(ran[a] < ran[b]){
        par[a] = b;
    }else if(ran[b] < ran[a]){
        par[b] = a;
    }else{
        par[a] = b;
        ran[b]++;
    }
}

int construct(vector<vi> p){
    int n = p.size();
    FOR(i,0,n){
        par[i] = i;
        ran[i] = 1;
        type[i] = 0;
    }
    vector<vi> ans(n,vi(n,0));
    FOR(i,0,n){
        FOR(j,0,n){
            if(p[i][j] == 2){
                uni(i,j);
                if(type[i] == 1 || type[j] == 1){
                    return 0;
                }
                type[i] = type[j] = 2;
            }
            if(p[i][j] == 1 && i != j){
                uni(i,j);
                if(type[i] == 2 || type[j] == 2){
                    return 0;
                }
                type[i] = type[j] = 1;
            }
        }
    }
    bool vis[n] = {};
    vector<vi> conp(n,vi(n,0));
    FOR(i,0,n){
        if(!vis[par[i]]){
            vis[par[i]] = true;
            vi nodes;
            set<int> tmp;
            FOR(j,0,n){
                if(par[j] == par[i]){
                    nodes.pb(j);
                    tmp.insert(type[j]);
                }
            }
            if(tmp.size() != 1){
                return 0;
            }
            int tt = *tmp.begin();
            int sz = nodes.size();
            if(sz == 1){
                conp[nodes[0]][nodes[0]] = 1;
                continue;
            }
            if(sz == 2 && tt == 2){
                return 0;
            }
            FOR(ind,0,nodes.size()){
                if(ind != 0){
                    ans[nodes[ind]][nodes[ind-1]] = 1;
                }else if(tt == 2){
                    ans[nodes[ind]][nodes[sz-1]] = 1;
                }
                if(ind != (sz-1)){
                    ans[nodes[ind]][nodes[ind+1]] = 1;
                }else if(tt == 2){
                    ans[nodes[ind]][nodes[0]] = 1;
                }
                FOR(iind,0,sz){
                    if(ind == iind){
                        conp[nodes[ind]][nodes[iind]] = 1;
                        continue;
                    }
                    if(tt == 2){
                        conp[nodes[ind]][nodes[iind]] = 2;
                    }else{
                        conp[nodes[ind]][nodes[iind]] = 1;
                    }
                }
            }

        }
    }
    /*
    FOR(i,0,n){
        FOR(j,0,n){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }*/
    if(p != conp){
        return 0;
    }
    build(ans);
    return 1;
}

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:21:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 | #define FOR(i,a,b) for (int i = a; i < b; i++)
......
  144 |             FOR(ind,0,nodes.size()){
      |                 ~~~~~~~~~~~~~~~~~~    
supertrees.cpp:144:13: note: in expansion of macro 'FOR'
  144 |             FOR(ind,0,nodes.size()){
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...