Submission #731690

# Submission time Handle Problem Language Result Execution time Memory
731690 2023-04-27T19:23:07 Z danikoynov Vision Program (IOI19_vision) C++14
100 / 100
78 ms 7888 KB
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;

int H, W;

bool valid_cell(int x, int y)
{
    if (x >= 0 && x < H &&
        y >= 0 && y < W)
            return true;
    return false;
}

int left_diagonal_one(int sum)
{
    vector < int > cells;
    for (int x = 0; x < H; x ++)
    {
        int y = sum - x;
        if (valid_cell(x, y))
        {
            cells.push_back(x * W + y);
        }
    }
    /**cout << "query one " << endl;
    for (int v : cells)
    {
        cout << v / M << " " << v % M << endl;
    }*/

    return add_or(cells);
}

int left_diagonal_two(int sum)
{
    vector < int > cells;
    for (int x = 0; x < H; x ++)
    {
        int y = sum - x;
        if (valid_cell(x, y))
        {
            cells.push_back(x * W + y);
        }
    }

    int f1 = add_or(cells), f2 = add_xor(cells);
    int f3 = add_not(f2);
    vector < int > fin;
    fin.push_back(f1);
    fin.push_back(f3);
    return add_and(fin);
}

int right_diagonal_one(int diff)
{
    vector < int > cells;
    for (int x = 0; x < H; x ++)
    {
        int y = x + diff;
        if (valid_cell(x, y))
        {
            cells.push_back(x * W + y);
        }
    }
    /**cout << "query one " << endl;
    for (int v : cells)
    {
        cout << v / M << " " << v % M << endl;
    }*/

    return add_or(cells);
}

int right_diagonal_two(int diff)
{
    vector < int > cells;
    for (int x = 0; x < H; x ++)
    {
        int y = x + diff;
        if (valid_cell(x, y))
        {
            cells.push_back(x * W + y);
        }
    }

    int f1 = add_or(cells), f2 = add_xor(cells);
    int f3 = add_not(f2);
    vector < int > fin;
    fin.push_back(f1);
    fin.push_back(f3);
    return add_and(fin);
}

const int maxn = 1000;
int dig[2][2][maxn * 2];

void build_diagonals()
{
    for (int diff = W - 1; diff >= - H + 1; diff --)
    {
        dig[0][0][diff + maxn] = right_diagonal_one(diff);
        dig[1][0][diff + maxn] = right_diagonal_two(diff);
    }

    for (int sum = 0; sum <= H + W - 2; sum ++)
    {
        dig[0][1][sum + maxn] = left_diagonal_one(sum);
        dig[1][1][sum + maxn] = left_diagonal_two(sum);
    }
}

int get_right_gate(int dis)
{
    vector < int > con;
    for (int diff = W - 1; diff >= - H + 1; diff --)
    {
        vector < int > var, double_row;
        for (int cur = diff; cur >= - H + 1 && var.size() <= dis; cur --)
        {
            int v1 = dig[0][0][cur + maxn], v2 = dig[1][0][cur + maxn];
            con.push_back(v2);
            var.push_back(v1);
        }
        if (var.size() <= dis)
            break;

        int atl = add_or(var);
        int xort = add_xor(var);
        xort = add_not(xort);
        vector < int > mg;
        mg.push_back(atl);
        mg.push_back(xort);
        int comb = add_and(mg);
        mg.clear();
        con.push_back(comb);
        ///con.push_back(is_double);
        ///con.push_back(add_or(mg));
    }
    return add_or(con);
}

int get_left_gate(int dis)
{
    vector < int > con;
    for (int sum = 0; sum <= H + W - 2; sum ++)
    {
        vector < int > var, double_row;
        for (int cur = sum; cur <= H + W - 2 && var.size() <= dis; cur ++)
        {
            int v1 = dig[0][1][cur + maxn], v2 = dig[1][1][cur + maxn];
            double_row.push_back(v2);
            var.push_back(v1);
        }

        if (var.size() <= dis)
            break;

        int atl = add_or(var);
        int xort = add_xor(var);
        xort = add_not(xort);
        vector < int > mg;
        mg.push_back(atl);
        mg.push_back(xort);
        int comb = add_and(mg), is_double = add_or(double_row);
        mg.clear();
        con.push_back(comb);
        con.push_back(is_double);
        //con.push_back(add_or(mg));
    }
    return add_or(con);
}
int check(int dis)
{
    int gate_right = get_right_gate(dis);

    int gate_left = get_left_gate(dis);

    vector < int > fin;
    fin.push_back(gate_left);

    fin.push_back(gate_right);
    return add_and(fin);
}
void construct_network(int h, int w, int K)
{
    H = h;
    W = w;


    build_diagonals();
    if (K == 1)
    {
        int is_less = check(K);
        return;
    }
    int is_above = check(K - 1);

    int is_less = check(K);

    int not_above = add_not(is_above);
    vector < int > fin;
    fin.push_back(not_above);
    fin.push_back(is_less);
    add_and(fin);

}

Compilation message

vision.cpp: In function 'int get_right_gate(int)':
vision.cpp:119:59: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  119 |         for (int cur = diff; cur >= - H + 1 && var.size() <= dis; cur --)
      |                                                ~~~~~~~~~~~^~~~~~
vision.cpp:125:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  125 |         if (var.size() <= dis)
      |             ~~~~~~~~~~~^~~~~~
vision.cpp: In function 'int get_left_gate(int)':
vision.cpp:149:60: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  149 |         for (int cur = sum; cur <= H + W - 2 && var.size() <= dis; cur ++)
      |                                                 ~~~~~~~~~~~^~~~~~
vision.cpp:156:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  156 |         if (var.size() <= dis)
      |             ~~~~~~~~~~~^~~~~~
vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:194:13: warning: unused variable 'is_less' [-Wunused-variable]
  194 |         int is_less = check(K);
      |             ^~~~~~~
# 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 240 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 240 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 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 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 240 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 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 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 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 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 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 240 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 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 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 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 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 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 16 ms 2000 KB Output is correct
39 Correct 3 ms 596 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 6 ms 840 KB Output is correct
42 Correct 5 ms 724 KB Output is correct
43 Correct 8 ms 1108 KB Output is correct
44 Correct 16 ms 2012 KB Output is correct
45 Correct 18 ms 2228 KB Output is correct
46 Correct 15 ms 1876 KB Output is correct
47 Correct 7 ms 1012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 13 ms 1492 KB Output is correct
3 Correct 14 ms 1492 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 4 ms 720 KB Output is correct
6 Correct 12 ms 1488 KB Output is correct
7 Correct 11 ms 1364 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 13 ms 1336 KB Output is correct
11 Correct 16 ms 1504 KB Output is correct
12 Correct 12 ms 1620 KB Output is correct
13 Correct 9 ms 1236 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 12 ms 1360 KB Output is correct
17 Correct 14 ms 1620 KB Output is correct
18 Correct 14 ms 1592 KB Output is correct
19 Correct 9 ms 1200 KB Output is correct
20 Correct 2 ms 468 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 1 ms 212 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 7 ms 932 KB Output is correct
5 Correct 10 ms 980 KB Output is correct
6 Correct 9 ms 852 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 5 ms 852 KB Output is correct
9 Correct 12 ms 1488 KB Output is correct
10 Correct 15 ms 1640 KB Output is correct
11 Correct 13 ms 1416 KB Output is correct
12 Correct 5 ms 724 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 13 ms 1488 KB Output is correct
15 Correct 11 ms 1364 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 12 ms 1492 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 15 ms 1792 KB Output is correct
21 Correct 36 ms 4216 KB Output is correct
22 Correct 35 ms 4088 KB Output is correct
23 Correct 15 ms 1708 KB Output is correct
24 Correct 14 ms 1744 KB Output is correct
25 Correct 38 ms 4456 KB Output is correct
26 Correct 13 ms 1628 KB Output is correct
27 Correct 25 ms 3104 KB Output is correct
28 Correct 60 ms 6724 KB Output is correct
29 Correct 65 ms 7872 KB Output is correct
30 Correct 58 ms 6592 KB Output is correct
31 Correct 25 ms 2912 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3152 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 8 ms 852 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 14 ms 1872 KB Output is correct
8 Correct 17 ms 1792 KB Output is correct
9 Correct 27 ms 3144 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 240 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 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 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 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 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 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 16 ms 2000 KB Output is correct
39 Correct 3 ms 596 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 6 ms 840 KB Output is correct
42 Correct 5 ms 724 KB Output is correct
43 Correct 8 ms 1108 KB Output is correct
44 Correct 16 ms 2012 KB Output is correct
45 Correct 18 ms 2228 KB Output is correct
46 Correct 15 ms 1876 KB Output is correct
47 Correct 7 ms 1012 KB Output is correct
48 Correct 2 ms 596 KB Output is correct
49 Correct 13 ms 1492 KB Output is correct
50 Correct 14 ms 1492 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 4 ms 720 KB Output is correct
53 Correct 12 ms 1488 KB Output is correct
54 Correct 11 ms 1364 KB Output is correct
55 Correct 2 ms 468 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 13 ms 1336 KB Output is correct
58 Correct 16 ms 1504 KB Output is correct
59 Correct 12 ms 1620 KB Output is correct
60 Correct 9 ms 1236 KB Output is correct
61 Correct 2 ms 468 KB Output is correct
62 Correct 2 ms 596 KB Output is correct
63 Correct 12 ms 1360 KB Output is correct
64 Correct 14 ms 1620 KB Output is correct
65 Correct 14 ms 1592 KB Output is correct
66 Correct 9 ms 1200 KB Output is correct
67 Correct 2 ms 468 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 1 ms 212 KB Output is correct
72 Correct 3 ms 596 KB Output is correct
73 Correct 7 ms 932 KB Output is correct
74 Correct 10 ms 980 KB Output is correct
75 Correct 9 ms 852 KB Output is correct
76 Correct 6 ms 468 KB Output is correct
77 Correct 5 ms 852 KB Output is correct
78 Correct 12 ms 1488 KB Output is correct
79 Correct 15 ms 1640 KB Output is correct
80 Correct 13 ms 1416 KB Output is correct
81 Correct 5 ms 724 KB Output is correct
82 Correct 3 ms 596 KB Output is correct
83 Correct 13 ms 1488 KB Output is correct
84 Correct 11 ms 1364 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 2 ms 596 KB Output is correct
87 Correct 12 ms 1492 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 15 ms 1792 KB Output is correct
90 Correct 36 ms 4216 KB Output is correct
91 Correct 35 ms 4088 KB Output is correct
92 Correct 15 ms 1708 KB Output is correct
93 Correct 14 ms 1744 KB Output is correct
94 Correct 38 ms 4456 KB Output is correct
95 Correct 13 ms 1628 KB Output is correct
96 Correct 25 ms 3104 KB Output is correct
97 Correct 60 ms 6724 KB Output is correct
98 Correct 65 ms 7872 KB Output is correct
99 Correct 58 ms 6592 KB Output is correct
100 Correct 25 ms 2912 KB Output is correct
101 Correct 1 ms 212 KB Output is correct
102 Correct 1 ms 212 KB Output is correct
103 Correct 25 ms 3152 KB Output is correct
104 Correct 1 ms 212 KB Output is correct
105 Correct 3 ms 596 KB Output is correct
106 Correct 8 ms 852 KB Output is correct
107 Correct 2 ms 596 KB Output is correct
108 Correct 3 ms 596 KB Output is correct
109 Correct 14 ms 1872 KB Output is correct
110 Correct 17 ms 1792 KB Output is correct
111 Correct 27 ms 3144 KB Output is correct
112 Correct 0 ms 212 KB Output is correct
113 Correct 1 ms 212 KB Output is correct
114 Correct 62 ms 6872 KB Output is correct
115 Correct 2 ms 468 KB Output is correct
116 Correct 4 ms 724 KB Output is correct
117 Correct 27 ms 3104 KB Output is correct
118 Correct 31 ms 3400 KB Output is correct
119 Correct 71 ms 7740 KB Output is correct
120 Correct 66 ms 7768 KB Output is correct
121 Correct 70 ms 7888 KB Output is correct
122 Correct 72 ms 7780 KB Output is correct
123 Correct 27 ms 3144 KB Output is correct
124 Correct 78 ms 6828 KB Output is correct
125 Correct 73 ms 7884 KB Output is correct
126 Correct 68 ms 7848 KB Output is correct
127 Correct 59 ms 6504 KB Output is correct
128 Correct 26 ms 2892 KB Output is correct