Submission #427193

# Submission time Handle Problem Language Result Execution time Memory
427193 2021-06-14T13:19:19 Z Aldas25 Vision Program (IOI19_vision) C++14
100 / 100
74 ms 5232 KB
#include "vision.h"
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;

const int MAXN = 500100;

int h, w, k;

int getId (int i, int j) {
    return i*w + j;
}

void construct_network(int H, int W, int K) {
    h = H, w = W, k = K;

    /// 0..H*W-1 - grid

    vi istr1, istr2;
    FOR(i, 0, h+w-2) {
        int x, y;
        if (i < w) {
            x = 0;
            y = w - i - 1;
        } else {
            y = 0;
            x = i - w + 1;
        }
        vi ids;
        while (x < h && y < w) {
            ids.pb(getId(x, y));
            x++; y++;
        }

        //cout << " istr i = " << i << ": ";
        //for (int x : ids) cout << x << " ";
        //cout << endl;

        int id = add_or(ids);
        //cout << " id = " << id << endl;
        istr1.pb(id);
    }

    FOR(i, 0, h+w-2) {
        int x, y;
        if (i < h) {
            x = i;
            y = 0;
        } else {
            x = h-1;
            y = i - x;
        }
        vi ids;
        while (x >= 0 && y < w) {
            ids.pb(getId(x, y));
            x--; y++;
        }

        //cout << " istr i = " << i << ": ";
        //for (int x : ids) cout << x << " ";
        //cout << endl;

        int id = add_or(ids);
        //cout << " id = " << id << endl;
        istr2.pb(id);
    }




    vi istrXOR1, istrXOR2;
    FOR(i, 0, h+w-2) {
        int x, y;
        if (i < w) {
            x = 0;
            y = w - i - 1;
        } else {
            y = 0;
            x = i - w + 1;
        }
        vi ids;
        while (x < h && y < w) {
            ids.pb(getId(x, y));
            x++; y++;
        }

        //cout << " istr i = " << i << ": ";
        //for (int x : ids) cout << x << " ";
        //cout << endl;

        int id = add_xor(ids);
        //cout << " id = " << id << endl;
        istrXOR1.pb(id);
    }

    FOR(i, 0, h+w-2) {
        int x, y;
        if (i < h) {
            x = i;
            y = 0;
        } else {
            x = h-1;
            y = i - x;
        }
        vi ids;
        while (x >= 0 && y < w) {
            ids.pb(getId(x, y));
            x--; y++;
        }

        //cout << " istr i = " << i << ": ";
        //for (int x : ids) cout << x << " ";
        //cout << endl;

        int id = add_xor(ids);
        //cout << " id = " << id << endl;
        istrXOR2.pb(id);
    }





    vi istrPairs1, istrPairs2;
    FOR(i, 0, (int)istr1.size()-k-1) {
        vi toAnd = {istr1[i], istr1[i+k]};
        int id = add_and(toAnd);
        istrPairs1.pb(id);
    }

    int pairs1 = add_or(istrPairs1);

    FOR(i, 0, (int)istr2.size()-k-1) {
        vi toAnd = {istr2[i], istr2[i+k]};
        int id = add_and(toAnd);
        istrPairs2.pb(id);
    }

    int pairs2 = add_or(istrPairs2);

    vi groups1;
    FOR(i, 0, (int)istrXOR1.size()-1) {
        vi ids;
        FOR(j, max(0, i-k), min((int)istrXOR1.size()-1, i+k))
            ids.pb(istrXOR1[j]);
        int id = add_xor(ids);
        id = add_not(id);
        vi toAnd = {id, istr1[i]};
        id = add_and(toAnd);
        groups1.pb(id);
    }

    vi groups2;
    FOR(i, 0, (int)istrXOR2.size()-1) {
        vi ids;
        FOR(j, max(0, i-k), min((int)istrXOR2.size()-1, i+k))
            ids.pb(istrXOR2[j]);
        int id = add_xor(ids);
        id = add_not(id);
        vi toAnd = {id, istr2[i]};
        id = add_and(toAnd);
        groups2.pb(id);
    }

    int gr1 = add_or(groups1);
    int gr2 = add_or(groups2);

    vi toAnd1 = {pairs1, gr2};
    vi toAnd2 = {pairs2, gr1};
    int id1 = add_and(toAnd1);
    int id2 = add_and(toAnd2);
    vi toOr = {id1, id2};
    add_or(toOr);

}

/*

2 3 3
0 0 0 1
0 0 0 2
0 0 1 0
0 0 1 1
0 0 1 2
0 1 0 2
0 1 1 0
0 1 1 1
0 1 1 2
0 2 1 0
0 2 1 1
0 2 1 2
1 0 1 1
1 0 1 2
1 1 1 2
-1
out:
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0




in:
2 3 1
0 0 0 1
0 0 0 2
0 0 1 0
0 0 1 1
0 0 1 2
0 1 0 2
0 1 1 0
0 1 1 1
0 1 1 2
0 2 1 0
0 2 1 1
0 2 1 2
1 0 1 1
1 0 1 2
1 1 1 2
-1
out:


2 3 1
0 2 1 0
-1

2 3 2
0 0 1 1

2 3 2
0 0 0 1
0 0 0 2
0 0 1 0
0 0 1 1
0 0 1 2
0 1 0 2
0 1 1 0
0 1 1 1
0 1 1 2
0 2 1 0
0 2 1 1
0 2 1 2
1 0 1 1
1 0 1 2
1 1 1 2
-1

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 2 ms 296 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 2 ms 296 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 10 ms 1100 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 5 ms 588 KB Output is correct
42 Correct 9 ms 844 KB Output is correct
43 Correct 7 ms 844 KB Output is correct
44 Correct 11 ms 1184 KB Output is correct
45 Correct 15 ms 1348 KB Output is correct
46 Correct 15 ms 1612 KB Output is correct
47 Correct 17 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 8 ms 972 KB Output is correct
3 Correct 8 ms 972 KB Output is correct
4 Correct 11 ms 948 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 10 ms 816 KB Output is correct
7 Correct 10 ms 1052 KB Output is correct
8 Correct 14 ms 952 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 6 ms 716 KB Output is correct
11 Correct 9 ms 972 KB Output is correct
12 Correct 8 ms 972 KB Output is correct
13 Correct 10 ms 1100 KB Output is correct
14 Correct 12 ms 1100 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 8 ms 676 KB Output is correct
17 Correct 8 ms 972 KB Output is correct
18 Correct 9 ms 972 KB Output is correct
19 Correct 10 ms 1100 KB Output is correct
20 Correct 11 ms 972 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 588 KB Output is correct
5 Correct 8 ms 604 KB Output is correct
6 Correct 6 ms 716 KB Output is correct
7 Correct 6 ms 716 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 8 ms 932 KB Output is correct
10 Correct 10 ms 972 KB Output is correct
11 Correct 11 ms 1072 KB Output is correct
12 Correct 14 ms 1100 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 6 ms 716 KB Output is correct
15 Correct 11 ms 1004 KB Output is correct
16 Correct 11 ms 972 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 9 ms 972 KB Output is correct
19 Correct 11 ms 972 KB Output is correct
20 Correct 12 ms 1228 KB Output is correct
21 Correct 26 ms 2316 KB Output is correct
22 Correct 30 ms 2792 KB Output is correct
23 Correct 31 ms 2964 KB Output is correct
24 Correct 12 ms 1228 KB Output is correct
25 Correct 27 ms 2640 KB Output is correct
26 Correct 32 ms 3096 KB Output is correct
27 Correct 22 ms 2152 KB Output is correct
28 Correct 40 ms 3516 KB Output is correct
29 Correct 49 ms 4424 KB Output is correct
30 Correct 56 ms 5076 KB Output is correct
31 Correct 60 ms 5232 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2176 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 5 ms 716 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 528 KB Output is correct
7 Correct 12 ms 1228 KB Output is correct
8 Correct 14 ms 1296 KB Output is correct
9 Correct 22 ms 2184 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 2 ms 296 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 10 ms 1100 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 5 ms 588 KB Output is correct
42 Correct 9 ms 844 KB Output is correct
43 Correct 7 ms 844 KB Output is correct
44 Correct 11 ms 1184 KB Output is correct
45 Correct 15 ms 1348 KB Output is correct
46 Correct 15 ms 1612 KB Output is correct
47 Correct 17 ms 1536 KB Output is correct
48 Correct 3 ms 460 KB Output is correct
49 Correct 8 ms 972 KB Output is correct
50 Correct 8 ms 972 KB Output is correct
51 Correct 11 ms 948 KB Output is correct
52 Correct 2 ms 460 KB Output is correct
53 Correct 10 ms 816 KB Output is correct
54 Correct 10 ms 1052 KB Output is correct
55 Correct 14 ms 952 KB Output is correct
56 Correct 2 ms 460 KB Output is correct
57 Correct 6 ms 716 KB Output is correct
58 Correct 9 ms 972 KB Output is correct
59 Correct 8 ms 972 KB Output is correct
60 Correct 10 ms 1100 KB Output is correct
61 Correct 12 ms 1100 KB Output is correct
62 Correct 2 ms 460 KB Output is correct
63 Correct 8 ms 676 KB Output is correct
64 Correct 8 ms 972 KB Output is correct
65 Correct 9 ms 972 KB Output is correct
66 Correct 10 ms 1100 KB Output is correct
67 Correct 11 ms 972 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 1 ms 204 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 4 ms 460 KB Output is correct
73 Correct 4 ms 588 KB Output is correct
74 Correct 8 ms 604 KB Output is correct
75 Correct 6 ms 716 KB Output is correct
76 Correct 6 ms 716 KB Output is correct
77 Correct 5 ms 716 KB Output is correct
78 Correct 8 ms 932 KB Output is correct
79 Correct 10 ms 972 KB Output is correct
80 Correct 11 ms 1072 KB Output is correct
81 Correct 14 ms 1100 KB Output is correct
82 Correct 2 ms 460 KB Output is correct
83 Correct 6 ms 716 KB Output is correct
84 Correct 11 ms 1004 KB Output is correct
85 Correct 11 ms 972 KB Output is correct
86 Correct 2 ms 460 KB Output is correct
87 Correct 9 ms 972 KB Output is correct
88 Correct 11 ms 972 KB Output is correct
89 Correct 12 ms 1228 KB Output is correct
90 Correct 26 ms 2316 KB Output is correct
91 Correct 30 ms 2792 KB Output is correct
92 Correct 31 ms 2964 KB Output is correct
93 Correct 12 ms 1228 KB Output is correct
94 Correct 27 ms 2640 KB Output is correct
95 Correct 32 ms 3096 KB Output is correct
96 Correct 22 ms 2152 KB Output is correct
97 Correct 40 ms 3516 KB Output is correct
98 Correct 49 ms 4424 KB Output is correct
99 Correct 56 ms 5076 KB Output is correct
100 Correct 60 ms 5232 KB Output is correct
101 Correct 1 ms 204 KB Output is correct
102 Correct 1 ms 204 KB Output is correct
103 Correct 22 ms 2176 KB Output is correct
104 Correct 1 ms 204 KB Output is correct
105 Correct 3 ms 460 KB Output is correct
106 Correct 5 ms 716 KB Output is correct
107 Correct 2 ms 460 KB Output is correct
108 Correct 2 ms 528 KB Output is correct
109 Correct 12 ms 1228 KB Output is correct
110 Correct 14 ms 1296 KB Output is correct
111 Correct 22 ms 2184 KB Output is correct
112 Correct 1 ms 204 KB Output is correct
113 Correct 1 ms 204 KB Output is correct
114 Correct 38 ms 3480 KB Output is correct
115 Correct 11 ms 972 KB Output is correct
116 Correct 2 ms 548 KB Output is correct
117 Correct 45 ms 3032 KB Output is correct
118 Correct 19 ms 1868 KB Output is correct
119 Correct 49 ms 4472 KB Output is correct
120 Correct 51 ms 4456 KB Output is correct
121 Correct 59 ms 4436 KB Output is correct
122 Correct 48 ms 4536 KB Output is correct
123 Correct 35 ms 2116 KB Output is correct
124 Correct 40 ms 3516 KB Output is correct
125 Correct 49 ms 4472 KB Output is correct
126 Correct 50 ms 4460 KB Output is correct
127 Correct 55 ms 5056 KB Output is correct
128 Correct 74 ms 5188 KB Output is correct