Submission #304568

# Submission time Handle Problem Language Result Execution time Memory
304568 2020-09-21T14:13:38 Z DeD_TihoN Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
272 ms 22524 KB
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define endl '\n'
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define y1 asjdlfaskavslbcjasndscf
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter set< int >::iterator
#define iter1 multiset<int>::iterator
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

//const int MAX_MEM=4e8;
//int mpos=0;
//char mem[MAX_MEM];
//
//inline void * operator new(size_t n){
//    char *res=mem+mpos;
//    mpos+=n;
//    if (mpos>=MAX_MEM){
//        cout<<"BAD"<<endl;
//        exit(0);
//    }
//    return (void*)res;
//}
//
//inline void operator delete(void *) {}

const int N=1000+5;
const int inf=1e9+1e9;
const int mod=1e9+7;
const ld eps=1e-9;

#define COL 1

#if COL

#include "supertrees.h"
#include <vector>

#endif

void add(int x,int y,vector<vector<int>>&ans)
{
    if (x==y)return;
    ans[x][y]=1;
    ans[y][x]=1;
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		ans.push_back(row);
	}
	bitset<N>used1[n],used2[n];
	bool used[n],used3[n];
	int nxt[n];
	fill(used,used+n,0);
	fill(used3,used3+n,0);
	fill(nxt,nxt+n,-1);
	for (int i=0;i<n;++i){
        for (int j=0;j<n;++j){
            if (p[i][j]==1){
                used1[i][j]=1;
            }
            if (p[i][j]==2){
                used2[i][j]=1;
            }
            if (p[i][j]==3){
                return 0;
            }
        }
	}
    for (int i=0;i<n;++i){
        if (used3[i])continue;
        vector<int>ver;
        for (int j=0;j<n;++j){
            if (used1[i][j]){
                ver.pb(j);
            }
        }
        if (!used[i]){
            for (int j=0;j<ver.size();++j){
                int to=ver[j];
                used3[to]=1;
                if (used1[to]!=used1[i]){
                    return 0;
                }
                if (used2[to]!=used2[i]){
                    return 0;
                }
                add(i,to,ans);
            }
            used[i]=1;
        }
    }
    for (int i=0;i<n;++i){
        if (used[i]){
            nxt[i]=i;
            for (int j=i+1;j<n;++j){
                if (used[j]){
                    if ((used1[j]|used2[j])==(used1[i]|used2[i])){
                        nxt[i]=j;
                        break;
                    }
                }
            }
            if (nxt[i]==i){
                for (int j=0;j<i;++j){
                    if (used[j]){
                        if ((used1[j]|used2[j])==(used1[i]|used2[i])){
                            nxt[i]=j;
                            break;
                        }
                    }
                }
            }
        }
    }
    for (int i=0;i<n;++i){
        used3[i]=0;
    }
    for (int i=0;i<n;++i){
        if (used[i]){
            add(i,nxt[i],ans);
        }
        if (used3[i])continue;
        if (used[i]){
            int kol=1;
            used3[i]=1;
            bitset<N>c=used1[i];
            int v=nxt[i];
            while (v!=i){
                used3[v]=1;
                c|=used1[v];
                v=nxt[v];
                ++kol;
            }
            c|=used1[i];
            if (kol==2){
                return 0;
            }
            bitset<N>r=(used1[i]|used2[i]);
            if (c!=(used1[i]|used2[i])){
                return 0;
            }
        }
    }
	#if !COL
	for (int i=0;i<ans.size();++i){
        for (int j=0;j<ans.size();++j){
            cout<<ans[i][j]<<' ';
        }
        cout<<endl;
	}
	#endif
	#if COL
	build(ans);
	#endif
	return 1;
}

#if !COL
main ()
{
    ios;
    construct({
    {1,1,2,2},
    {1,1,2,2},
    {2,2,1,2},
    {2,2,2,1},
    });

}
#endif

//4
//1 2 1 0
//1 3 1 0
//3 4 1 1

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:109:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |             for (int j=0;j<ver.size();++j){
      |                          ~^~~~~~~~~~~
supertrees.cpp:169:22: warning: variable 'r' set but not used [-Wunused-but-set-variable]
  169 |             bitset<N>r=(used1[i]|used2[i]);
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 258 ms 22392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 258 ms 22392 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 246 ms 22340 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 122 ms 12380 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 84 ms 5880 KB Output is correct
21 Correct 245 ms 22392 KB Output is correct
22 Correct 240 ms 22392 KB Output is correct
23 Correct 252 ms 22524 KB Output is correct
24 Correct 245 ms 22392 KB Output is correct
25 Correct 108 ms 12408 KB Output is correct
26 Correct 97 ms 12512 KB Output is correct
27 Correct 248 ms 22392 KB Output is correct
28 Correct 272 ms 22392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 245 ms 22392 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 251 ms 22392 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 6 ms 896 KB Output is correct
17 Correct 122 ms 12376 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 60 ms 5880 KB Output is correct
22 Correct 238 ms 22392 KB Output is correct
23 Correct 255 ms 22392 KB Output is correct
24 Correct 258 ms 22392 KB Output is correct
25 Correct 109 ms 12408 KB Output is correct
26 Correct 101 ms 12408 KB Output is correct
27 Correct 241 ms 22392 KB Output is correct
28 Correct 250 ms 22472 KB Output is correct
29 Correct 104 ms 12408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 61 ms 5880 KB Output is correct
5 Correct 242 ms 22424 KB Output is correct
6 Correct 235 ms 22392 KB Output is correct
7 Correct 253 ms 22392 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 73 ms 5880 KB Output is correct
10 Correct 250 ms 22364 KB Output is correct
11 Correct 244 ms 22360 KB Output is correct
12 Correct 249 ms 22360 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 60 ms 6008 KB Output is correct
17 Correct 240 ms 22392 KB Output is correct
18 Correct 238 ms 22396 KB Output is correct
19 Correct 239 ms 22400 KB Output is correct
20 Correct 243 ms 22520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 258 ms 22392 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 246 ms 22340 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 122 ms 12380 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 84 ms 5880 KB Output is correct
21 Correct 245 ms 22392 KB Output is correct
22 Correct 240 ms 22392 KB Output is correct
23 Correct 252 ms 22524 KB Output is correct
24 Correct 245 ms 22392 KB Output is correct
25 Correct 108 ms 12408 KB Output is correct
26 Correct 97 ms 12512 KB Output is correct
27 Correct 248 ms 22392 KB Output is correct
28 Correct 272 ms 22392 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 245 ms 22392 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 251 ms 22392 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 6 ms 896 KB Output is correct
45 Correct 122 ms 12376 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 60 ms 5880 KB Output is correct
50 Correct 238 ms 22392 KB Output is correct
51 Correct 255 ms 22392 KB Output is correct
52 Correct 258 ms 22392 KB Output is correct
53 Correct 109 ms 12408 KB Output is correct
54 Correct 101 ms 12408 KB Output is correct
55 Correct 241 ms 22392 KB Output is correct
56 Correct 250 ms 22472 KB Output is correct
57 Correct 104 ms 12408 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 5 ms 896 KB Output is correct
61 Correct 118 ms 12408 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 1 ms 256 KB Output is correct
64 Correct 0 ms 256 KB Output is correct
65 Correct 64 ms 5884 KB Output is correct
66 Correct 99 ms 12408 KB Output is correct
67 Correct 99 ms 12508 KB Output is correct
68 Correct 97 ms 12408 KB Output is correct
69 Correct 105 ms 12384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 258 ms 22392 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 246 ms 22340 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 896 KB Output is correct
17 Correct 122 ms 12380 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 84 ms 5880 KB Output is correct
21 Correct 245 ms 22392 KB Output is correct
22 Correct 240 ms 22392 KB Output is correct
23 Correct 252 ms 22524 KB Output is correct
24 Correct 245 ms 22392 KB Output is correct
25 Correct 108 ms 12408 KB Output is correct
26 Correct 97 ms 12512 KB Output is correct
27 Correct 248 ms 22392 KB Output is correct
28 Correct 272 ms 22392 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 245 ms 22392 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 251 ms 22392 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 6 ms 896 KB Output is correct
45 Correct 122 ms 12376 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 60 ms 5880 KB Output is correct
50 Correct 238 ms 22392 KB Output is correct
51 Correct 255 ms 22392 KB Output is correct
52 Correct 258 ms 22392 KB Output is correct
53 Correct 109 ms 12408 KB Output is correct
54 Correct 101 ms 12408 KB Output is correct
55 Correct 241 ms 22392 KB Output is correct
56 Correct 250 ms 22472 KB Output is correct
57 Correct 104 ms 12408 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 1 ms 256 KB Output is correct
61 Correct 61 ms 5880 KB Output is correct
62 Correct 242 ms 22424 KB Output is correct
63 Correct 235 ms 22392 KB Output is correct
64 Correct 253 ms 22392 KB Output is correct
65 Correct 1 ms 256 KB Output is correct
66 Correct 73 ms 5880 KB Output is correct
67 Correct 250 ms 22364 KB Output is correct
68 Correct 244 ms 22360 KB Output is correct
69 Correct 249 ms 22360 KB Output is correct
70 Correct 0 ms 256 KB Output is correct
71 Correct 0 ms 256 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 60 ms 6008 KB Output is correct
74 Correct 240 ms 22392 KB Output is correct
75 Correct 238 ms 22396 KB Output is correct
76 Correct 239 ms 22400 KB Output is correct
77 Correct 243 ms 22520 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 0 ms 256 KB Output is correct
80 Correct 5 ms 896 KB Output is correct
81 Correct 118 ms 12408 KB Output is correct
82 Correct 1 ms 256 KB Output is correct
83 Correct 1 ms 256 KB Output is correct
84 Correct 0 ms 256 KB Output is correct
85 Correct 64 ms 5884 KB Output is correct
86 Correct 99 ms 12408 KB Output is correct
87 Correct 99 ms 12508 KB Output is correct
88 Correct 97 ms 12408 KB Output is correct
89 Correct 105 ms 12384 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 0 ms 256 KB Output is correct
92 Correct 5 ms 896 KB Output is correct
93 Correct 113 ms 12408 KB Output is correct
94 Correct 1 ms 256 KB Output is correct
95 Correct 0 ms 256 KB Output is correct
96 Correct 0 ms 256 KB Output is correct
97 Correct 25 ms 3448 KB Output is correct
98 Correct 104 ms 12376 KB Output is correct
99 Correct 99 ms 12408 KB Output is correct
100 Correct 96 ms 12408 KB Output is correct
101 Correct 100 ms 12380 KB Output is correct
102 Correct 112 ms 12408 KB Output is correct
103 Correct 109 ms 12408 KB Output is correct
104 Correct 111 ms 12376 KB Output is correct
105 Correct 109 ms 12408 KB Output is correct