Submission #658937

# Submission time Handle Problem Language Result Execution time Memory
658937 2022-11-15T13:00:58 Z jiahng Vision Program (IOI19_vision) C++14
100 / 100
58 ms 5956 KB
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 201
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;

int H,W;
bool valid(int x,int y){
    return (x >= 0 && x < H && y >= 0 && y < W);
}
int ordiag1[maxn][maxn],ordiag2[maxn][maxn],xordiag1[maxn][maxn],xordiag2[maxn][maxn];
void construct_network(int H, int W, int K) {
    vi ans;
    ::H = H; ::W = W;
    // precomp OR and XOR in each diagonal
    for (int si=0,sj=W-1;si<H;(sj==0?si++:sj--)){
        vi v;
        for (int i=si,j=sj;valid(i,j);i++,j++) v.pb(i*W+j);
        ordiag1[si][sj] = add_or(v);
        xordiag1[si][sj] = add_xor(v);
    }

    for (int si=0,sj=0;si<H;(sj==W-1?si++:sj++)){ // antidiagonal
        vi v;
        for (int i=si,j=sj;valid(i,j);i++,j--) v.pb(i*W+j);
        ordiag2[si][sj] = add_or(v);
        xordiag2[si][sj] = add_xor(v);
    }

    vi axis1_unstrict_or, axis2_strict_or;
    for (int si=0,sj=W-1;si<H;(sj==0?si++:sj--)){
        vi orv,xorv;
        for (int k=0;k<=K;k++){
            int diagi = si+k, diagj = sj;
            diagi -= diagj; diagj = 0;

            if (!valid(diagi, diagj)){
                diagj -= diagi; diagi = 0;
            }
            if (!valid(diagi, diagj)) continue;
            assert(diagi == 0 || diagj == 0);
            orv.pb(ordiag1[diagi][diagj]);
            xorv.pb(xordiag1[diagi][diagj]);
        }
        if (orv.empty()) continue;
        axis1_unstrict_or.pb(add_and({add_or(orv), add_not(add_xor(xorv))}));
    }
    int distleqK1 = add_or(axis1_unstrict_or);
    for (int si=0,sj=0;si<H;(sj==W-1?si++:sj++)){
        int diagi = si+K, diagj = sj;
        diagj += diagi; diagi = 0;
        if (!valid(diagi, diagj)){
            diagi -= (-diagj + W - 1);
            diagj = W-1; 
        }
        if (!valid(diagi, diagj)) continue;
        int or_idx = add_or({ordiag2[diagi][diagj], ordiag2[si][sj]});
        int xor_idx = add_xor({xordiag2[diagi][diagj], xordiag2[si][sj]});
        axis2_strict_or.pb(add_and({or_idx, add_not(xor_idx), xordiag2[si][sj]})); // Whether it is distance K on the axis
    }
    int distK2 = add_or(axis2_strict_or);
    int ok1 = add_and({distleqK1, distK2});

    vi axis2_unstrict_or, axis1_strict_or;

    for (int si=0,sj=0;si<H;(sj==W-1?si++:sj++)){ // antidiagonal
        vi orv,xorv;
        for (int k=0;k<=K;k++){
            int diagi = si+k, diagj = sj;
            diagj += diagi; diagi = 0;
            if (!valid(diagi, diagj)){
                diagi -= (-diagj + W - 1);
                diagj = W-1;
            }
            if (!valid(diagi, diagj)) continue;

            orv.pb(ordiag2[diagi][diagj]);
            xorv.pb(xordiag2[diagi][diagj]);
        }
        axis2_unstrict_or.pb(add_and({add_or(orv), add_not(add_xor(xorv))}));
    }
    int distleqK2 = add_or(axis2_unstrict_or);

    for (int si=0,sj=W-1;si<H;(sj==0?si++:sj--)){ // diagonal
        int diagi = si+K, diagj = sj;
        diagj -= diagi; diagi = 0;
        if (!valid(diagi, diagj)){
            diagi -= diagj;
            diagj = 0;
        }
        if (!valid(diagi, diagj)) continue;
        int or_idx = add_or({ordiag1[diagi][diagj], ordiag1[si][sj]});
        int xor_idx = add_xor({xordiag1[diagi][diagj], xordiag1[si][sj]});
        axis1_strict_or.pb(add_and({or_idx, add_not(xor_idx), xordiag1[si][sj]})); // Whether it is distance K on the axis
    }
    int distK1 = add_or(axis1_strict_or);
    int ok2 = add_and({distleqK2, distK1});
    
    add_or({ok1, ok2});
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 560 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 436 KB Output is correct
33 Correct 2 ms 432 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 436 KB Output is correct
37 Correct 2 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 560 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 436 KB Output is correct
33 Correct 2 ms 432 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 436 KB Output is correct
37 Correct 2 ms 432 KB Output is correct
38 Correct 10 ms 1492 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 4 ms 812 KB Output is correct
41 Correct 6 ms 948 KB Output is correct
42 Correct 8 ms 1188 KB Output is correct
43 Correct 6 ms 1236 KB Output is correct
44 Correct 9 ms 1584 KB Output is correct
45 Correct 11 ms 1748 KB Output is correct
46 Correct 12 ms 1872 KB Output is correct
47 Correct 13 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 9 ms 980 KB Output is correct
3 Correct 8 ms 976 KB Output is correct
4 Correct 8 ms 1188 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
6 Correct 6 ms 1492 KB Output is correct
7 Correct 8 ms 1620 KB Output is correct
8 Correct 9 ms 1748 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 8 ms 1040 KB Output is correct
12 Correct 8 ms 980 KB Output is correct
13 Correct 9 ms 1108 KB Output is correct
14 Correct 11 ms 1252 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 7 ms 1620 KB Output is correct
18 Correct 8 ms 1556 KB Output is correct
19 Correct 9 ms 1748 KB Output is correct
20 Correct 10 ms 1748 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 980 KB Output is correct
4 Correct 4 ms 980 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 7 ms 1052 KB Output is correct
7 Correct 6 ms 1068 KB Output is correct
8 Correct 5 ms 948 KB Output is correct
9 Correct 7 ms 1108 KB Output is correct
10 Correct 9 ms 1236 KB Output is correct
11 Correct 10 ms 1364 KB Output is correct
12 Correct 11 ms 1456 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 8 ms 1108 KB Output is correct
16 Correct 10 ms 1132 KB Output is correct
17 Correct 3 ms 1220 KB Output is correct
18 Correct 9 ms 1620 KB Output is correct
19 Correct 10 ms 1768 KB Output is correct
20 Correct 14 ms 2140 KB Output is correct
21 Correct 19 ms 3016 KB Output is correct
22 Correct 26 ms 3556 KB Output is correct
23 Correct 26 ms 3660 KB Output is correct
24 Correct 13 ms 1744 KB Output is correct
25 Correct 23 ms 2980 KB Output is correct
26 Correct 27 ms 3372 KB Output is correct
27 Correct 22 ms 3140 KB Output is correct
28 Correct 31 ms 4388 KB Output is correct
29 Correct 40 ms 5292 KB Output is correct
30 Correct 46 ms 5892 KB Output is correct
31 Correct 50 ms 5956 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3116 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 4 ms 1236 KB Output is correct
7 Correct 10 ms 2128 KB Output is correct
8 Correct 11 ms 1744 KB Output is correct
9 Correct 26 ms 3024 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 2 ms 312 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 560 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 436 KB Output is correct
33 Correct 2 ms 432 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 436 KB Output is correct
37 Correct 2 ms 432 KB Output is correct
38 Correct 10 ms 1492 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 4 ms 812 KB Output is correct
41 Correct 6 ms 948 KB Output is correct
42 Correct 8 ms 1188 KB Output is correct
43 Correct 6 ms 1236 KB Output is correct
44 Correct 9 ms 1584 KB Output is correct
45 Correct 11 ms 1748 KB Output is correct
46 Correct 12 ms 1872 KB Output is correct
47 Correct 13 ms 1876 KB Output is correct
48 Correct 4 ms 596 KB Output is correct
49 Correct 9 ms 980 KB Output is correct
50 Correct 8 ms 976 KB Output is correct
51 Correct 8 ms 1188 KB Output is correct
52 Correct 2 ms 1236 KB Output is correct
53 Correct 6 ms 1492 KB Output is correct
54 Correct 8 ms 1620 KB Output is correct
55 Correct 9 ms 1748 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 5 ms 852 KB Output is correct
58 Correct 8 ms 1040 KB Output is correct
59 Correct 8 ms 980 KB Output is correct
60 Correct 9 ms 1108 KB Output is correct
61 Correct 11 ms 1252 KB Output is correct
62 Correct 2 ms 1236 KB Output is correct
63 Correct 6 ms 1364 KB Output is correct
64 Correct 7 ms 1620 KB Output is correct
65 Correct 8 ms 1556 KB Output is correct
66 Correct 9 ms 1748 KB Output is correct
67 Correct 10 ms 1748 KB Output is correct
68 Correct 0 ms 212 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 3 ms 980 KB Output is correct
73 Correct 4 ms 980 KB Output is correct
74 Correct 5 ms 1108 KB Output is correct
75 Correct 7 ms 1052 KB Output is correct
76 Correct 6 ms 1068 KB Output is correct
77 Correct 5 ms 948 KB Output is correct
78 Correct 7 ms 1108 KB Output is correct
79 Correct 9 ms 1236 KB Output is correct
80 Correct 10 ms 1364 KB Output is correct
81 Correct 11 ms 1456 KB Output is correct
82 Correct 3 ms 596 KB Output is correct
83 Correct 6 ms 852 KB Output is correct
84 Correct 8 ms 1108 KB Output is correct
85 Correct 10 ms 1132 KB Output is correct
86 Correct 3 ms 1220 KB Output is correct
87 Correct 9 ms 1620 KB Output is correct
88 Correct 10 ms 1768 KB Output is correct
89 Correct 14 ms 2140 KB Output is correct
90 Correct 19 ms 3016 KB Output is correct
91 Correct 26 ms 3556 KB Output is correct
92 Correct 26 ms 3660 KB Output is correct
93 Correct 13 ms 1744 KB Output is correct
94 Correct 23 ms 2980 KB Output is correct
95 Correct 27 ms 3372 KB Output is correct
96 Correct 22 ms 3140 KB Output is correct
97 Correct 31 ms 4388 KB Output is correct
98 Correct 40 ms 5292 KB Output is correct
99 Correct 46 ms 5892 KB Output is correct
100 Correct 50 ms 5956 KB Output is correct
101 Correct 1 ms 212 KB Output is correct
102 Correct 1 ms 304 KB Output is correct
103 Correct 19 ms 3116 KB Output is correct
104 Correct 1 ms 212 KB Output is correct
105 Correct 4 ms 852 KB Output is correct
106 Correct 4 ms 852 KB Output is correct
107 Correct 2 ms 596 KB Output is correct
108 Correct 4 ms 1236 KB Output is correct
109 Correct 10 ms 2128 KB Output is correct
110 Correct 11 ms 1744 KB Output is correct
111 Correct 26 ms 3024 KB Output is correct
112 Correct 0 ms 212 KB Output is correct
113 Correct 0 ms 212 KB Output is correct
114 Correct 32 ms 4292 KB Output is correct
115 Correct 9 ms 1172 KB Output is correct
116 Correct 3 ms 1236 KB Output is correct
117 Correct 32 ms 3692 KB Output is correct
118 Correct 17 ms 2352 KB Output is correct
119 Correct 42 ms 5184 KB Output is correct
120 Correct 51 ms 5236 KB Output is correct
121 Correct 42 ms 5200 KB Output is correct
122 Correct 42 ms 5220 KB Output is correct
123 Correct 20 ms 3072 KB Output is correct
124 Correct 31 ms 4288 KB Output is correct
125 Correct 42 ms 5320 KB Output is correct
126 Correct 44 ms 5320 KB Output is correct
127 Correct 58 ms 5804 KB Output is correct
128 Correct 47 ms 5944 KB Output is correct