답안 #1019834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019834 2024-07-11T09:31:05 Z ProtonDecay314 Vision Program (IOI19_vision) C++17
100 / 100
18 ms 2400 KB
// AM+DG

/*

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
#define L(i, varmn, varmx) for(ll i = varmn; i < varmx; i++)
#define LR(i, varmx, varmn) for(ll i = varmx; i > varmn; i--)
#define LI(i, varmn, varmx) for(int i = varmn; i < varmx; i++)
#define LIR(i, varmx, varmn) for(int i = varmx; i > varmn; i--)
#define pb push_back
#include "vision.h"

int cellnum(int r, int c, int W) {
    return r * W + c;
}

void construct_network(int h, int w, int k) {
    // Falsy/truthy values, may help!
    int falsy = add_xor({0, 0});
    int truthy = add_not(falsy);

    // Row/col stuff
    vi row_has;
    LI(i, 0, h) {
        vi all_in_row;
        LI(j, 0, w) {
            all_in_row.pb(cellnum(i, j, w));
        }
        row_has.pb(add_or(all_in_row));
    }
    vi col_has;
    LI(i, 0, w) {
        vi all_in_col;
        LI(j, 0, h) all_in_col.pb(cellnum(j, i, w));
        col_has.pb(add_or(all_in_col));
    }


    int row_is_same = add_xor(row_has);
    int col_is_same = add_xor(col_has);

    // dist_from_orig[i] should OR all points that satisfy x + y = i
    vi dist_from_orig;
    LI(i, 0, h + w - 1) {
        vi all_in_diag;
        LI(x, 0, w) {
            int y = i - x;
            if(y < 0 || y >= h) continue;
            all_in_diag.pb(cellnum(y, x, w));
        }
        assert((int)all_in_diag.size() > 0);
        dist_from_orig.pb(add_or(all_in_diag));
    }

    // dist_from_p2[i] should OR all points that satisfy W - 1 - x + y = i -> y - x = i - W + 1 -> y = x + i - w + 1
    vi dist_from_p2;
    LI(i, 0, h + w - 1) {
        vi all_in_diag;
        LI(x, 0, w) {
            int y = i + x - w + 1;
            if(y < 0 || y >= h) continue;
            all_in_diag.pb(cellnum(y, x, w));
        }
        assert((int)all_in_diag.size() > 0);
        dist_from_p2.pb(add_or(all_in_diag));
    }

    // Next step: determine whether the precondition for necessary condition 1 is true
    // Necessary condition 1: the horizontal and vertical distances must both be no more than k
    
    /// To do this, we can create "sliding windows". Over these sliding windows, we compute the "or" and "xor"
    /// If the "or" is 1 and the "xor" is 0 for any of the sliding windows, we know that the two points are within that sliding window and thus have a separation of no more than k
    int r_is_bounded;
    if(k < h) {
        vi nc1r;
        LI(i, 0, h - k) {
            // In the current window, we will consider the range [i, i + k]
            vi window;
            LI(j, i, i + k + 1) {
                window.pb(row_has[j]);
            }

            int cur_or = add_or(window);
            int cur_xor = add_xor(window);
            int is_contained = add_and({cur_or, add_not(cur_xor)});

            nc1r.pb(is_contained);
        }
        

        r_is_bounded = add_or({row_is_same, add_or(nc1r)});
    } else {
        r_is_bounded = truthy;
    }

    int c_is_bounded;
    if(k < w) {
        vi nc1c;
        LI(i, 0, w - k) {
            // In the current window, we will consider the range [i, i + k]
            vi window;
            LI(j, i, i + k + 1) {
                window.pb(col_has[j]);
            }

            int cur_or = add_or(window);
            int cur_xor = add_xor(window);
            int is_contained = add_and({cur_or, add_not(cur_xor)});

            nc1c.pb(is_contained);
        }
        c_is_bounded = add_or({col_is_same, add_or(nc1c)});
    } else {
        c_is_bounded = truthy;
    }


    int oned_is_bounded = add_and({r_is_bounded, c_is_bounded});

    // Next step: determine whether the precondition for necessary condition 2 is true
    // Necessary condition 2: either the top-right diagonal distance is k or the top-left diagonal distance is k
    vi dist_orig_k_sep;

    LI(i, 0, h + w - 1 - k) {
        dist_orig_k_sep.pb(add_and({dist_from_orig[i], dist_from_orig[i + k]}));
    }
    assert((int)dist_orig_k_sep.size() > 0);

    int dist_orig_is_k_sep = add_or(dist_orig_k_sep);

    vi dist_p2_k_sep;

    LI(i, 0, h + w - 1 - k) {
        dist_p2_k_sep.pb(add_and({dist_from_p2[i], dist_from_p2[i + k]}));
    }
    assert((int)dist_p2_k_sep.size() > 0);

    int dist_p2_is_k_sep = add_or(dist_p2_k_sep);

    int dist_diag_is_k_sep = add_or({dist_orig_is_k_sep, dist_p2_is_k_sep});

    // Next step: determine whether both necessary conditions are true. This is the answer
    int yay_yippee_ac_happiness_yooo_nice_slay_yasss_win_bit = add_and({oned_is_bounded, dist_diag_is_k_sep});

    return;
}

Compilation message

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:154:9: warning: unused variable 'yay_yippee_ac_happiness_yooo_nice_slay_yasss_win_bit' [-Wunused-variable]
  154 |     int yay_yippee_ac_happiness_yooo_nice_slay_yasss_win_bit = add_and({oned_is_bounded, dist_diag_is_k_sep});
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 436 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 436 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 436 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 432 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 436 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 436 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 432 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 436 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 436 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 432 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 4 ms 856 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 692 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 3 ms 648 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 856 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 2 ms 648 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 6 ms 1372 KB Output is correct
21 Correct 7 ms 1372 KB Output is correct
22 Correct 5 ms 1116 KB Output is correct
23 Correct 5 ms 1116 KB Output is correct
24 Correct 6 ms 1372 KB Output is correct
25 Correct 7 ms 1372 KB Output is correct
26 Correct 5 ms 1116 KB Output is correct
27 Correct 11 ms 2228 KB Output is correct
28 Correct 14 ms 2396 KB Output is correct
29 Correct 11 ms 1880 KB Output is correct
30 Correct 13 ms 1884 KB Output is correct
31 Correct 10 ms 1880 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2140 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 6 ms 1372 KB Output is correct
8 Correct 6 ms 1372 KB Output is correct
9 Correct 18 ms 2240 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 436 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 436 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 432 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 4 ms 856 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 692 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 3 ms 648 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 2 ms 604 KB Output is correct
50 Correct 2 ms 604 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 2 ms 604 KB Output is correct
54 Correct 2 ms 600 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 2 ms 644 KB Output is correct
58 Correct 2 ms 604 KB Output is correct
59 Correct 4 ms 604 KB Output is correct
60 Correct 3 ms 604 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 2 ms 604 KB Output is correct
64 Correct 2 ms 604 KB Output is correct
65 Correct 2 ms 856 KB Output is correct
66 Correct 1 ms 600 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 2 ms 576 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 2 ms 604 KB Output is correct
78 Correct 2 ms 604 KB Output is correct
79 Correct 3 ms 604 KB Output is correct
80 Correct 2 ms 648 KB Output is correct
81 Correct 4 ms 600 KB Output is correct
82 Correct 1 ms 348 KB Output is correct
83 Correct 2 ms 604 KB Output is correct
84 Correct 2 ms 604 KB Output is correct
85 Correct 1 ms 432 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
87 Correct 2 ms 604 KB Output is correct
88 Correct 1 ms 436 KB Output is correct
89 Correct 6 ms 1372 KB Output is correct
90 Correct 7 ms 1372 KB Output is correct
91 Correct 5 ms 1116 KB Output is correct
92 Correct 5 ms 1116 KB Output is correct
93 Correct 6 ms 1372 KB Output is correct
94 Correct 7 ms 1372 KB Output is correct
95 Correct 5 ms 1116 KB Output is correct
96 Correct 11 ms 2228 KB Output is correct
97 Correct 14 ms 2396 KB Output is correct
98 Correct 11 ms 1880 KB Output is correct
99 Correct 13 ms 1884 KB Output is correct
100 Correct 10 ms 1880 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 11 ms 2140 KB Output is correct
104 Correct 0 ms 348 KB Output is correct
105 Correct 1 ms 604 KB Output is correct
106 Correct 2 ms 604 KB Output is correct
107 Correct 1 ms 348 KB Output is correct
108 Correct 1 ms 348 KB Output is correct
109 Correct 6 ms 1372 KB Output is correct
110 Correct 6 ms 1372 KB Output is correct
111 Correct 18 ms 2240 KB Output is correct
112 Correct 0 ms 344 KB Output is correct
113 Correct 1 ms 348 KB Output is correct
114 Correct 14 ms 2400 KB Output is correct
115 Correct 1 ms 344 KB Output is correct
116 Correct 1 ms 348 KB Output is correct
117 Correct 6 ms 1116 KB Output is correct
118 Correct 7 ms 1372 KB Output is correct
119 Correct 10 ms 1880 KB Output is correct
120 Correct 11 ms 1884 KB Output is correct
121 Correct 11 ms 1884 KB Output is correct
122 Correct 10 ms 1884 KB Output is correct
123 Correct 11 ms 2136 KB Output is correct
124 Correct 14 ms 2392 KB Output is correct
125 Correct 11 ms 2044 KB Output is correct
126 Correct 11 ms 1880 KB Output is correct
127 Correct 11 ms 2136 KB Output is correct
128 Correct 11 ms 1880 KB Output is correct