답안 #775994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775994 2023-07-07T08:13:06 Z _martynas Vision Program (IOI19_vision) C++14
100 / 100
63 ms 7432 KB
#include "vision.h"
#include <bits/stdc++.h>

using namespace std;

void visualize(int H, int W, vector<int> A) {
    vector<vector<char>> B(H, vector<char>(W, '.'));
    for(int x : A) B[x/W][x%W] = '#';
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cerr << B[i][j];
        }
        cerr << "\n";
    }
}

void construct_network(int H, int W, int K) {
    /* sample interaction
	std::vector<int> Ns;
	Ns = {0, 1};
	int a = add_and(Ns);
	Ns = {0, a};
	int b = add_or(Ns);
	Ns = {0, 1, b};
	int c = add_xor(Ns);
	add_not(c);
	*/
    vector<vector<int>> diag1, diag2;
    diag1 = diag2 = vector<vector<int>>(H+W-1);
    /*  diag1 (down right)  diag2 (down left)
        ---------           ---------
        |c|d|e|f|           |f|e|d|c|
        ---------           ---------
        |b|c|d|e|           |e|d|c|b|
        ---------           ---------
        |a|b|c|d|           |d|c|b|a|
        ---------           ---------
    */
    // diag1
    for(int i = 0; i < H; i++) {
        for(int x = H-i-1, y = 0; x < H && y < W; x++, y++) {
            diag1[i].push_back(x*W+y);
        }
    }
    for(int i = H; i < H+W-1; i++) {
        for(int x = 0, y = i-H+1; x < H && y < W; x++, y++) {
            diag1[i].push_back(x*W+y);
        }
    }
//    for(int i = 0; i < H+W-1; i++) {
//        cerr << i << ":\n";
//        visualize(H, W, diag1[i]);
//    }
    // diag2
    for(int i = 0; i < H; i++) {
        for(int x = H-i-1, y = W-1; x < H && y >= 0; x++, y--) {
            diag2[i].push_back(x*W+y);
        }
    }
    for(int i = H; i < H+W-1; i++) {
        for(int x = 0, y = W-(i-H)-2; x < H && y >= 0; x++, y--) {
            diag2[i].push_back(x*W+y);
        }
    }
//    for(int i = 0; i < H+W-1; i++) {
//        cerr << i << ":\n";
//        visualize(H, W, diag2[i]);
//    }
    /// Returns an index to the answer
    auto dist_less_than_K = [&]() {
        vector<int> diag1_or(H+W-1), diag2_or(H+W-1); // indices not values
        vector<int> diag1_xor(H+W-1), diag2_xor(H+W-1); // indices not values
        for(int i = 0; i < H+W-1; i++) {
            vector<int> query;
            for(int x : diag1[i]) query.push_back(x);
            diag1_or[i] = add_or(query);
            diag1_xor[i] = add_xor(query);
            query.clear();
            for(int x : diag2[i]) query.push_back(x);
            diag2_or[i] = add_or(query);
            diag2_xor[i] = add_xor(query);
        }
        vector<int> diag1_range_ok, diag2_range_ok; // indices not values
        for(int i = 0; i+K-1 < H+W-1; i++) {
            vector<int> query;
            for(int j = i; j < i+K; j++) query.push_back(diag1_or[j]);
            int range_or = add_or(query);
            query.clear();
            for(int j = i; j < i+K; j++) query.push_back(diag1_xor[j]);
            int range_xor = add_xor(query);
            diag1_range_ok.push_back(add_and(vector<int>{range_or, add_not(range_xor)}));
        }
        for(int i = 0; i+K-1 < H+W-1; i++) {
            vector<int> query;
            for(int j = i; j < i+K; j++) query.push_back(diag2_or[j]);
            int range_or = add_or(query);
            query.clear();
            for(int j = i; j < i+K; j++) query.push_back(diag2_xor[j]);
            int range_xor = add_xor(query);
            diag2_range_ok.push_back(add_and(vector<int>{range_or, add_not(range_xor)}));
        }
        int ok = add_and(vector<int>{add_or(diag1_range_ok), add_or(diag2_range_ok)});
        return ok;
    };
    int ok1 = dist_less_than_K();
    K++;
    int ok2 = dist_less_than_K();
    add_and(vector<int>{add_not(ok1), ok2});
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 1 ms 212 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 296 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 1 ms 212 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 296 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 432 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 428 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 404 KB Output is correct
37 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 1 ms 212 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 296 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 432 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 428 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 404 KB Output is correct
37 Correct 1 ms 296 KB Output is correct
38 Correct 15 ms 1944 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 5 ms 852 KB Output is correct
42 Correct 5 ms 812 KB Output is correct
43 Correct 8 ms 1488 KB Output is correct
44 Correct 13 ms 1900 KB Output is correct
45 Correct 14 ms 2096 KB Output is correct
46 Correct 12 ms 1876 KB Output is correct
47 Correct 7 ms 1196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 7 ms 1108 KB Output is correct
3 Correct 9 ms 1108 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 7 ms 1168 KB Output is correct
7 Correct 7 ms 1108 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 8 ms 1236 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 6 ms 1108 KB Output is correct
17 Correct 7 ms 1188 KB Output is correct
18 Correct 7 ms 1188 KB Output is correct
19 Correct 6 ms 940 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 5 ms 940 KB Output is correct
5 Correct 6 ms 920 KB Output is correct
6 Correct 5 ms 808 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 6 ms 1104 KB Output is correct
9 Correct 11 ms 1452 KB Output is correct
10 Correct 10 ms 1452 KB Output is correct
11 Correct 8 ms 1364 KB Output is correct
12 Correct 5 ms 852 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 6 ms 1072 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 7 ms 1196 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 17 ms 2504 KB Output is correct
21 Correct 27 ms 3960 KB Output is correct
22 Correct 27 ms 3796 KB Output is correct
23 Correct 14 ms 2216 KB Output is correct
24 Correct 16 ms 2512 KB Output is correct
25 Correct 28 ms 3996 KB Output is correct
26 Correct 14 ms 2120 KB Output is correct
27 Correct 29 ms 4556 KB Output is correct
28 Correct 46 ms 6728 KB Output is correct
29 Correct 62 ms 7344 KB Output is correct
30 Correct 46 ms 6504 KB Output is correct
31 Correct 27 ms 3992 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 4548 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 688 KB Output is correct
4 Correct 6 ms 1104 KB Output is correct
5 Correct 3 ms 680 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 15 ms 2512 KB Output is correct
8 Correct 15 ms 2456 KB Output is correct
9 Correct 28 ms 4540 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 296 KB Output is correct
22 Correct 1 ms 212 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 296 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 432 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 428 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 404 KB Output is correct
37 Correct 1 ms 296 KB Output is correct
38 Correct 15 ms 1944 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 5 ms 852 KB Output is correct
42 Correct 5 ms 812 KB Output is correct
43 Correct 8 ms 1488 KB Output is correct
44 Correct 13 ms 1900 KB Output is correct
45 Correct 14 ms 2096 KB Output is correct
46 Correct 12 ms 1876 KB Output is correct
47 Correct 7 ms 1196 KB Output is correct
48 Correct 2 ms 724 KB Output is correct
49 Correct 7 ms 1108 KB Output is correct
50 Correct 9 ms 1108 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 7 ms 1168 KB Output is correct
54 Correct 7 ms 1108 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 2 ms 724 KB Output is correct
57 Correct 8 ms 1108 KB Output is correct
58 Correct 8 ms 1236 KB Output is correct
59 Correct 8 ms 1108 KB Output is correct
60 Correct 6 ms 980 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 2 ms 724 KB Output is correct
63 Correct 6 ms 1108 KB Output is correct
64 Correct 7 ms 1188 KB Output is correct
65 Correct 7 ms 1188 KB Output is correct
66 Correct 6 ms 940 KB Output is correct
67 Correct 2 ms 468 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 296 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 3 ms 724 KB Output is correct
73 Correct 5 ms 940 KB Output is correct
74 Correct 6 ms 920 KB Output is correct
75 Correct 5 ms 808 KB Output is correct
76 Correct 3 ms 596 KB Output is correct
77 Correct 6 ms 1104 KB Output is correct
78 Correct 11 ms 1452 KB Output is correct
79 Correct 10 ms 1452 KB Output is correct
80 Correct 8 ms 1364 KB Output is correct
81 Correct 5 ms 852 KB Output is correct
82 Correct 3 ms 724 KB Output is correct
83 Correct 7 ms 1108 KB Output is correct
84 Correct 6 ms 1072 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 2 ms 724 KB Output is correct
87 Correct 7 ms 1196 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 17 ms 2504 KB Output is correct
90 Correct 27 ms 3960 KB Output is correct
91 Correct 27 ms 3796 KB Output is correct
92 Correct 14 ms 2216 KB Output is correct
93 Correct 16 ms 2512 KB Output is correct
94 Correct 28 ms 3996 KB Output is correct
95 Correct 14 ms 2120 KB Output is correct
96 Correct 29 ms 4556 KB Output is correct
97 Correct 46 ms 6728 KB Output is correct
98 Correct 62 ms 7344 KB Output is correct
99 Correct 46 ms 6504 KB Output is correct
100 Correct 27 ms 3992 KB Output is correct
101 Correct 1 ms 212 KB Output is correct
102 Correct 0 ms 212 KB Output is correct
103 Correct 36 ms 4548 KB Output is correct
104 Correct 1 ms 340 KB Output is correct
105 Correct 3 ms 688 KB Output is correct
106 Correct 6 ms 1104 KB Output is correct
107 Correct 3 ms 680 KB Output is correct
108 Correct 2 ms 724 KB Output is correct
109 Correct 15 ms 2512 KB Output is correct
110 Correct 15 ms 2456 KB Output is correct
111 Correct 28 ms 4540 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 0 ms 212 KB Output is correct
114 Correct 47 ms 6744 KB Output is correct
115 Correct 2 ms 468 KB Output is correct
116 Correct 2 ms 724 KB Output is correct
117 Correct 22 ms 3192 KB Output is correct
118 Correct 24 ms 3452 KB Output is correct
119 Correct 51 ms 7292 KB Output is correct
120 Correct 52 ms 7344 KB Output is correct
121 Correct 51 ms 7332 KB Output is correct
122 Correct 63 ms 7368 KB Output is correct
123 Correct 29 ms 4556 KB Output is correct
124 Correct 46 ms 6680 KB Output is correct
125 Correct 52 ms 7432 KB Output is correct
126 Correct 61 ms 7384 KB Output is correct
127 Correct 46 ms 6476 KB Output is correct
128 Correct 27 ms 4044 KB Output is correct