Submission #469820

#TimeUsernameProblemLanguageResultExecution timeMemory
469820AdamGSConnecting Supertrees (IOI20_supertrees)C++14
100 / 100
316 ms26020 KiB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
int construct(vector<vector<int>>p) {
        int n=p[0].size();
        rep(i, n) rep(j, n) if(p[i][j]==3) return 0;
        vector<pair<vector<int>,int>>V;
        rep(i, n) {
                vector<int>a;
                rep(j, n) if(p[i][j]) a.pb(1); else a.pb(0);
                V.pb({a, i});
        }
        sort(all(V));
        vector<vector<int>>spojne;
        vector<int>akt1=V[0].st, akt2;
        akt2.pb(V[0].nd);
        for(int i=1; i<V.size(); ++i) {
                if(V[i].st!=akt1) {
                        vector<int>jakie;
                        rep(j, n) if(akt1[j]) jakie.pb(j);
                        if(jakie!=akt2) return 0;
                        spojne.pb(akt2);
                        akt1=V[i].st;
                        akt2.clear();
                }
                akt2.pb(V[i].nd);
        }
        vector<int>jakie;
        rep(j, n) if(akt1[j]) jakie.pb(j);
        if(jakie!=akt2) return 0;
        spojne.pb(akt2);
        vector<vector<int>>ans;
        rep(i, n) {
                vector<int>a;
                rep(j, n) a.pb(0);
                ans.pb(a);
        }
        for(auto i : spojne) {
                V.clear();
                akt1.clear();
                akt2.clear();
                for(auto j : i) {
                        vector<int>a;
                        rep(l, n) a.pb(p[j][l]);
                        V.pb({a, j});
                }
                sort(all(V));
                vector<vector<int>>drzewa;
                akt1=V[0].st;
                akt2.pb(V[0].nd);
                for(int j=1; j<V.size(); ++j) {
                        if(V[j].st!=akt1) {
                                jakie.clear();
                                rep(l, n) if(akt1[l]==1) jakie.pb(l);
                                if(jakie!=akt2) return 0;
                                drzewa.pb(akt2);
                                akt1=V[j].st;
                                akt2.clear();
                        }
                        akt2.pb(V[j].nd);
                }
                jakie.clear();
                rep(j, n) if(akt1[j]==1) jakie.pb(j);
                if(jakie!=akt2) return 0;
                drzewa.pb(akt2);
                for(auto j : drzewa) {
                        int ile=0;
                        rep(l, n) if(p[j[0]][l]==1) ++ile;
                        if(ile!=j.size()) return 0;
                        rep(l, j.size()-1) {
                                ans[j[l]][j[l+1]]=ans[j[l+1]][j[l]]=1;
                        }
                }
                if(drzewa.size()==2) return 0;
                if(drzewa.size()!=1) rep(j, drzewa.size()) {
                        ans[drzewa[j][0]][drzewa[(j+1)%drzewa.size()][0]]=1;
                        ans[drzewa[(j+1)%drzewa.size()][0]][drzewa[j][0]]=1;
                }
        }
        build(ans);
        return 1;
}

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for(int i=1; i<V.size(); ++i) {
      |                      ~^~~~~~~~~
supertrees.cpp:58:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                 for(int j=1; j<V.size(); ++j) {
      |                              ~^~~~~~~~~
supertrees.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |                         if(ile!=j.size()) return 0;
      |                            ~~~^~~~~~~~~~
supertrees.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
supertrees.cpp:77:25: note: in expansion of macro 'rep'
   77 |                         rep(l, j.size()-1) {
      |                         ^~~
supertrees.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
supertrees.cpp:82:38: note: in expansion of macro 'rep'
   82 |                 if(drzewa.size()!=1) rep(j, drzewa.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...