Submission #1062918

# Submission time Handle Problem Language Result Execution time Memory
1062918 2024-08-17T11:52:54 Z ewirlan Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
192 ms 22268 KB
//
#ifndef __SIZEOF_INT128__
  #define __SIZEOF_INT128__
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template <typename T> using oset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i, p, k) for(int i(p); i < (k); ++i)
#define per(i, p, k) for(int i(p); i > (k); --i)
#define sz(x) (int)(x).size()
#define sc static_cast
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __int128_t lll;
//#define int ll
template <typename T = int> using par = std::pair <T, T>;
#define fi first
#define se second
#define test int _number_of_tests(in()); while(_number_of_tests--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb emplace_back
struct Timer {
    string name{""};
    time_point<high_resolution_clock> end, start{high_resolution_clock::now()};
    duration<float, std::milli> dur;
    Timer() = default;
    Timer(string nm): name(nm) {}
    ~Timer() {
        end = high_resolution_clock::now(); dur= end - start;
        cout << "@" << name << "> " << dur.count() << " ms" << '\n';
    }
};
template <typename T = int> inline T in()
{
    static T x;
    std::cin >> x;
    return x;
}
std::string yn(bool b)
{
    if(b) return "YES\n";
    else return "NO\n";
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par);
template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek)
{
    for(const auto& i : wek)out << i << ' ';
    return out;
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par)
{
    out << '{'<<par.first<<", "<<par.second<<"}";
    return out;
}
#define show(x) cerr << #x << " = " << x << '\n';
#include "supertrees.h"
constexpr int maxn = 1003;
int gr[maxn];
vector <int> za[maxn];
int sp[maxn];
vector <int> po[maxn];
int construct(vector <vector <int>> p)
{
    int n(sz(p));
    rep(i, 0, n)rep(j, 0, n)if(p[i][j] == 3)return 0;
    rep(i, 0, n)gr[i] = sp[i] = -1;
    vector <int> g, c;
    rep(i, 0, n)if(gr[i] == -1){
        rep(j, 0, n)if(p[i][j] == 1){
            gr[j] = i;
            za[i].pb(j);
        }
        g.pb(i);
    }
    rep(i, 0, n)rep(j, 0, n)if((gr[i] == gr[j]) != (p[i][j] == 1)){
        // cerr << "A " << i << ' ' << j << '\n';
        return 0;
    }
    for(auto i: g)if(sp[i] == -1){
        for(auto j: g)if(p[i][j]){
            sp[j] = i;
            po[i].pb(j);
        }
        c.pb(i);
    }
    // rep(i, 0, n)cerr << gr[i] << ' ';
    // cerr << '\n';
    rep(i, 0, n)rep(j, 0, n)if(gr[i] != gr[j] && (sp[gr[i]] == sp[gr[j]]) != (p[i][j] == 2)){
        // cerr << "B " << i << ' ' << j << '\n';
        return 0;
    }
    vector <vector<int>> b(n, vector <int>(n, 0));
    auto kr = [&](int x, int y){
        b[x][y] = b[y][x] = 1;
    };
    for(auto i: g){
        rep(j, 1, sz(za[i]))kr(za[i][j-1],za[i][j]);
    }
    for(auto i: c){
        if(sz(po[i]) == 2)return 0;
        if(sz(po[i]) >= 3)rep(j, 0, sz(po[i]))kr(po[i][j], po[i][(j+1)%sz(po[i])]);
    }
    build(b);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 5 ms 1164 KB Output is correct
7 Correct 132 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 5 ms 1164 KB Output is correct
7 Correct 132 ms 22220 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 118 ms 22064 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 53 ms 8276 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 30 ms 5740 KB Output is correct
21 Correct 138 ms 22096 KB Output is correct
22 Correct 141 ms 22100 KB Output is correct
23 Correct 128 ms 22104 KB Output is correct
24 Correct 132 ms 22232 KB Output is correct
25 Correct 80 ms 8272 KB Output is correct
26 Correct 58 ms 8276 KB Output is correct
27 Correct 144 ms 22096 KB Output is correct
28 Correct 118 ms 22100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 142 ms 22096 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1208 KB Output is correct
13 Correct 125 ms 22092 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 54 ms 8268 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 29 ms 5980 KB Output is correct
22 Correct 115 ms 22268 KB Output is correct
23 Correct 132 ms 22100 KB Output is correct
24 Correct 192 ms 22072 KB Output is correct
25 Correct 67 ms 12352 KB Output is correct
26 Correct 51 ms 8276 KB Output is correct
27 Correct 129 ms 22092 KB Output is correct
28 Correct 124 ms 22096 KB Output is correct
29 Correct 61 ms 12352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 28 ms 5724 KB Output is correct
5 Correct 115 ms 22080 KB Output is correct
6 Correct 124 ms 22168 KB Output is correct
7 Correct 118 ms 22096 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 28 ms 5724 KB Output is correct
10 Correct 127 ms 22096 KB Output is correct
11 Correct 154 ms 22088 KB Output is correct
12 Correct 130 ms 22096 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 412 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 5980 KB Output is correct
17 Correct 132 ms 22080 KB Output is correct
18 Correct 121 ms 22096 KB Output is correct
19 Correct 114 ms 22104 KB Output is correct
20 Correct 141 ms 22092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 5 ms 1164 KB Output is correct
7 Correct 132 ms 22220 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 118 ms 22064 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 53 ms 8276 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 30 ms 5740 KB Output is correct
21 Correct 138 ms 22096 KB Output is correct
22 Correct 141 ms 22100 KB Output is correct
23 Correct 128 ms 22104 KB Output is correct
24 Correct 132 ms 22232 KB Output is correct
25 Correct 80 ms 8272 KB Output is correct
26 Correct 58 ms 8276 KB Output is correct
27 Correct 144 ms 22096 KB Output is correct
28 Correct 118 ms 22100 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 142 ms 22096 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1208 KB Output is correct
41 Correct 125 ms 22092 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 54 ms 8268 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 29 ms 5980 KB Output is correct
50 Correct 115 ms 22268 KB Output is correct
51 Correct 132 ms 22100 KB Output is correct
52 Correct 192 ms 22072 KB Output is correct
53 Correct 67 ms 12352 KB Output is correct
54 Correct 51 ms 8276 KB Output is correct
55 Correct 129 ms 22092 KB Output is correct
56 Correct 124 ms 22096 KB Output is correct
57 Correct 61 ms 12352 KB Output is correct
58 Correct 1 ms 600 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 3 ms 604 KB Output is correct
61 Correct 50 ms 8256 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 29 ms 5828 KB Output is correct
66 Correct 60 ms 8272 KB Output is correct
67 Correct 48 ms 8276 KB Output is correct
68 Correct 47 ms 8276 KB Output is correct
69 Correct 78 ms 12372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 5 ms 1164 KB Output is correct
7 Correct 132 ms 22220 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 118 ms 22064 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 53 ms 8276 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 30 ms 5740 KB Output is correct
21 Correct 138 ms 22096 KB Output is correct
22 Correct 141 ms 22100 KB Output is correct
23 Correct 128 ms 22104 KB Output is correct
24 Correct 132 ms 22232 KB Output is correct
25 Correct 80 ms 8272 KB Output is correct
26 Correct 58 ms 8276 KB Output is correct
27 Correct 144 ms 22096 KB Output is correct
28 Correct 118 ms 22100 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1372 KB Output is correct
37 Correct 142 ms 22096 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1208 KB Output is correct
41 Correct 125 ms 22092 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 54 ms 8268 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 29 ms 5980 KB Output is correct
50 Correct 115 ms 22268 KB Output is correct
51 Correct 132 ms 22100 KB Output is correct
52 Correct 192 ms 22072 KB Output is correct
53 Correct 67 ms 12352 KB Output is correct
54 Correct 51 ms 8276 KB Output is correct
55 Correct 129 ms 22092 KB Output is correct
56 Correct 124 ms 22096 KB Output is correct
57 Correct 61 ms 12352 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 28 ms 5724 KB Output is correct
62 Correct 115 ms 22080 KB Output is correct
63 Correct 124 ms 22168 KB Output is correct
64 Correct 118 ms 22096 KB Output is correct
65 Correct 0 ms 600 KB Output is correct
66 Correct 28 ms 5724 KB Output is correct
67 Correct 127 ms 22096 KB Output is correct
68 Correct 154 ms 22088 KB Output is correct
69 Correct 130 ms 22096 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 412 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 30 ms 5980 KB Output is correct
74 Correct 132 ms 22080 KB Output is correct
75 Correct 121 ms 22096 KB Output is correct
76 Correct 114 ms 22104 KB Output is correct
77 Correct 141 ms 22092 KB Output is correct
78 Correct 1 ms 600 KB Output is correct
79 Correct 1 ms 344 KB Output is correct
80 Correct 3 ms 604 KB Output is correct
81 Correct 50 ms 8256 KB Output is correct
82 Correct 1 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 29 ms 5828 KB Output is correct
86 Correct 60 ms 8272 KB Output is correct
87 Correct 48 ms 8276 KB Output is correct
88 Correct 47 ms 8276 KB Output is correct
89 Correct 78 ms 12372 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 652 KB Output is correct
93 Correct 49 ms 8268 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 19 ms 2904 KB Output is correct
98 Correct 48 ms 10320 KB Output is correct
99 Correct 53 ms 10304 KB Output is correct
100 Correct 51 ms 10072 KB Output is correct
101 Correct 65 ms 10320 KB Output is correct
102 Correct 47 ms 10068 KB Output is correct
103 Correct 49 ms 10320 KB Output is correct
104 Correct 55 ms 10324 KB Output is correct
105 Correct 63 ms 10176 KB Output is correct