Submission #1075871

# Submission time Handle Problem Language Result Execution time Memory
1075871 2024-08-26T09:35:03 Z j_vdd16 Vision Program (IOI19_vision) C++17
100 / 100
29 ms 3028 KB
#include "vision.h"

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

//#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;

typedef uint64_t u64;
typedef int64_t i64;

vi rows, cols;
void construct_network(int H, int W, int K) {
    rows = vi(H);
    loop(i, H) {
        vi Ns;
        loop(j, W) {
            Ns.push_back(i * W + j);
        }

        rows[i] = add_or(Ns);
        //add_log(rows[i]);
    }
    cols = vi(W);
    loop(j, W) {
        vi Ns;
        loop(i, H) {
            Ns.push_back(i * W + j);
        }

        cols[j] = add_or(Ns);
        //add_log(cols[j]);
    }

    vi rowBits;
    loop(bit, 8) {
        vi ands;
        loop(i, H - (1 << bit)) {
            vi rs;
            for (int j = i + (1 << bit); j < H; j += 2 * (1 << bit)) {
                for (int j2 = j; j2 < min(H, j + (1 << bit)); j2++) {
                    rs.push_back(rows[j2]);
                }
            }
            if (rs.size() == 0) {
                break;
            }

            int l = rows[i];
            int r = add_or(rs);

            ands.push_back(add_and({l, r}));
        }

        if (ands.size() == 0) {
            break;
        }
        rowBits.push_back(add_or(ands));
        //add_log(rowBits.back());
    }

    vi colBits;
    loop(bit, 8) {
        vi ands;
        loop(i, W - (1 << bit)) {
            vi rs;
            for (int j = i + (1 << bit); j < W; j += 2 * (1 << bit)) {
                for (int j2 = j; j2 < min(W, j + (1 << bit)); j2++) {
                    rs.push_back(cols[j2]);
                }
            }
            if (rs.size() == 0) {
                break;
            }

            int l = cols[i];
            int r = add_or(rs);

            ands.push_back(add_and({l, r}));
        }

        if (ands.size() == 0) {
            break;
        }
        colBits.push_back(add_or(ands));
        //add_log(colBits.back());
    }

    const int zero = add_not(add_or(rows));
    if (colBits.size() > rowBits.size()) {
        swap(colBits, rowBits);
    }

    vi sum;
    int carry = zero;
    loop(bit, colBits.size()) {
        sum.push_back(add_xor({colBits[bit], rowBits[bit], carry}));
        carry = add_or({
            add_and({colBits[bit], rowBits[bit]}), 
            add_and({colBits[bit], carry}), 
            add_and({carry, rowBits[bit]})
        });
    }
    for (int bit = colBits.size(); bit < rowBits.size(); bit++) {
        sum.push_back(add_xor({rowBits[bit], carry}));
        carry = add_and({rowBits[bit], carry});
    }
    sum.push_back(carry);

    loop(bit, sum.size()) {
        if ((K & (1 << bit)) == 0) {
            sum[bit] = add_not(sum[bit]);
        }
    }

    if (K >= (1 << sum.size())) {
        add_not(add_not(zero));
        return;
    }

    add_and(sum);
}

Compilation message

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:19:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 | #define loop(X, N) for(int X = 0; X < (N); X++)
      |                                     ^
vision.cpp:120:5: note: in expansion of macro 'loop'
  120 |     loop(bit, colBits.size()) {
      |     ^~~~
vision.cpp:128:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |     for (int bit = colBits.size(); bit < rowBits.size(); bit++) {
      |                                    ~~~~^~~~~~~~~~~~~~~~
vision.cpp:19:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 | #define loop(X, N) for(int X = 0; X < (N); X++)
      |                                     ^
vision.cpp:134:5: note: in expansion of macro 'loop'
  134 |     loop(bit, sum.size()) {
      |     ^~~~
# 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 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 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 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 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 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 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 348 KB Output is correct
37 Correct 2 ms 348 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 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 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 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 4 ms 1112 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 4 ms 604 KB Output is correct
43 Correct 7 ms 860 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 4 ms 856 KB Output is correct
46 Correct 4 ms 1116 KB Output is correct
47 Correct 4 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1116 KB Output is correct
2 Correct 6 ms 1116 KB Output is correct
3 Correct 9 ms 1368 KB Output is correct
4 Correct 9 ms 1116 KB Output is correct
5 Correct 7 ms 1140 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 5 ms 1116 KB Output is correct
8 Correct 5 ms 1112 KB Output is correct
9 Correct 5 ms 1116 KB Output is correct
10 Correct 5 ms 1116 KB Output is correct
11 Correct 10 ms 1116 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 5 ms 1112 KB Output is correct
14 Correct 5 ms 1116 KB Output is correct
15 Correct 9 ms 1116 KB Output is correct
16 Correct 10 ms 1116 KB Output is correct
17 Correct 5 ms 1112 KB Output is correct
18 Correct 7 ms 1112 KB Output is correct
19 Correct 11 ms 1116 KB Output is correct
20 Correct 5 ms 1112 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 3 ms 860 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Correct 5 ms 1116 KB Output is correct
14 Correct 5 ms 1116 KB Output is correct
15 Correct 5 ms 1116 KB Output is correct
16 Correct 5 ms 1116 KB Output is correct
17 Correct 5 ms 984 KB Output is correct
18 Correct 5 ms 1116 KB Output is correct
19 Correct 5 ms 1112 KB Output is correct
20 Correct 8 ms 1748 KB Output is correct
21 Correct 9 ms 1912 KB Output is correct
22 Correct 9 ms 1752 KB Output is correct
23 Correct 8 ms 1752 KB Output is correct
24 Correct 9 ms 1748 KB Output is correct
25 Correct 9 ms 1748 KB Output is correct
26 Correct 8 ms 1748 KB Output is correct
27 Correct 14 ms 2960 KB Output is correct
28 Correct 16 ms 2776 KB Output is correct
29 Correct 14 ms 2776 KB Output is correct
30 Correct 15 ms 2888 KB Output is correct
31 Correct 13 ms 2772 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2884 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 4 ms 860 KB Output is correct
5 Correct 4 ms 1116 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 9 ms 1752 KB Output is correct
8 Correct 8 ms 1752 KB Output is correct
9 Correct 14 ms 2772 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 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 1 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 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 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 4 ms 1112 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 4 ms 604 KB Output is correct
43 Correct 7 ms 860 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 4 ms 856 KB Output is correct
46 Correct 4 ms 1116 KB Output is correct
47 Correct 4 ms 1116 KB Output is correct
48 Correct 5 ms 1116 KB Output is correct
49 Correct 6 ms 1116 KB Output is correct
50 Correct 9 ms 1368 KB Output is correct
51 Correct 9 ms 1116 KB Output is correct
52 Correct 7 ms 1140 KB Output is correct
53 Correct 5 ms 1116 KB Output is correct
54 Correct 5 ms 1116 KB Output is correct
55 Correct 5 ms 1112 KB Output is correct
56 Correct 5 ms 1116 KB Output is correct
57 Correct 5 ms 1116 KB Output is correct
58 Correct 10 ms 1116 KB Output is correct
59 Correct 6 ms 1116 KB Output is correct
60 Correct 5 ms 1112 KB Output is correct
61 Correct 5 ms 1116 KB Output is correct
62 Correct 9 ms 1116 KB Output is correct
63 Correct 10 ms 1116 KB Output is correct
64 Correct 5 ms 1112 KB Output is correct
65 Correct 7 ms 1112 KB Output is correct
66 Correct 11 ms 1116 KB Output is correct
67 Correct 5 ms 1112 KB Output is correct
68 Correct 0 ms 344 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 2 ms 604 KB Output is correct
73 Correct 2 ms 604 KB Output is correct
74 Correct 2 ms 604 KB Output is correct
75 Correct 2 ms 604 KB Output is correct
76 Correct 4 ms 604 KB Output is correct
77 Correct 3 ms 860 KB Output is correct
78 Correct 3 ms 860 KB Output is correct
79 Correct 3 ms 860 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 4 ms 860 KB Output is correct
82 Correct 5 ms 1116 KB Output is correct
83 Correct 5 ms 1116 KB Output is correct
84 Correct 5 ms 1116 KB Output is correct
85 Correct 5 ms 1116 KB Output is correct
86 Correct 5 ms 984 KB Output is correct
87 Correct 5 ms 1116 KB Output is correct
88 Correct 5 ms 1112 KB Output is correct
89 Correct 8 ms 1748 KB Output is correct
90 Correct 9 ms 1912 KB Output is correct
91 Correct 9 ms 1752 KB Output is correct
92 Correct 8 ms 1752 KB Output is correct
93 Correct 9 ms 1748 KB Output is correct
94 Correct 9 ms 1748 KB Output is correct
95 Correct 8 ms 1748 KB Output is correct
96 Correct 14 ms 2960 KB Output is correct
97 Correct 16 ms 2776 KB Output is correct
98 Correct 14 ms 2776 KB Output is correct
99 Correct 15 ms 2888 KB Output is correct
100 Correct 13 ms 2772 KB Output is correct
101 Correct 1 ms 344 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 13 ms 2884 KB Output is correct
104 Correct 0 ms 348 KB Output is correct
105 Correct 2 ms 604 KB Output is correct
106 Correct 4 ms 860 KB Output is correct
107 Correct 4 ms 1116 KB Output is correct
108 Correct 5 ms 1116 KB Output is correct
109 Correct 9 ms 1752 KB Output is correct
110 Correct 8 ms 1752 KB Output is correct
111 Correct 14 ms 2772 KB Output is correct
112 Correct 0 ms 348 KB Output is correct
113 Correct 0 ms 348 KB Output is correct
114 Correct 14 ms 2776 KB Output is correct
115 Correct 5 ms 1116 KB Output is correct
116 Correct 5 ms 1116 KB Output is correct
117 Correct 11 ms 1752 KB Output is correct
118 Correct 9 ms 1752 KB Output is correct
119 Correct 14 ms 2776 KB Output is correct
120 Correct 14 ms 2776 KB Output is correct
121 Correct 13 ms 3028 KB Output is correct
122 Correct 14 ms 2776 KB Output is correct
123 Correct 15 ms 2776 KB Output is correct
124 Correct 29 ms 2776 KB Output is correct
125 Correct 22 ms 2884 KB Output is correct
126 Correct 15 ms 2776 KB Output is correct
127 Correct 14 ms 2772 KB Output is correct
128 Correct 13 ms 2776 KB Output is correct