Submission #731688

# Submission time Handle Problem Language Result Execution time Memory
731688 2023-04-27T19:20:02 Z danikoynov Vision Program (IOI19_vision) C++14
73 / 100
40 ms 4548 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];
            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();
        mg.push_back(comb);
        mg.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();
        mg.push_back(comb);
        mg.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 1 ms 212 KB Output is correct
3 Correct 1 ms 300 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 304 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 304 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 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 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 1 ms 300 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 304 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 304 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 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 300 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 304 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 1 ms 212 KB Output is correct
3 Correct 1 ms 300 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 304 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 304 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 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 300 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 304 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 3 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 432 KB Output is correct
35 Correct 5 ms 428 KB Output is correct
36 Correct 3 ms 428 KB Output is correct
37 Correct 2 ms 340 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 1 ms 300 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 304 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 304 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 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 300 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 304 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 3 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 432 KB Output is correct
35 Correct 5 ms 428 KB Output is correct
36 Correct 3 ms 428 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 17 ms 2000 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 3 ms 556 KB Output is correct
41 Correct 7 ms 888 KB Output is correct
42 Correct 5 ms 724 KB Output is correct
43 Correct 9 ms 1104 KB Output is correct
44 Correct 24 ms 2064 KB Output is correct
45 Correct 20 ms 2304 KB Output is correct
46 Correct 16 ms 1876 KB Output is correct
47 Correct 8 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 13 ms 1616 KB Output is correct
3 Correct 14 ms 1588 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 4 ms 816 KB Output is correct
6 Correct 13 ms 1560 KB Output is correct
7 Correct 12 ms 1404 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 12 ms 1428 KB Output is correct
11 Correct 13 ms 1632 KB Output is correct
12 Correct 13 ms 1616 KB Output is correct
13 Correct 10 ms 1316 KB Output is correct
14 Correct 3 ms 432 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 12 ms 1488 KB Output is correct
17 Correct 16 ms 1616 KB Output is correct
18 Correct 14 ms 1616 KB Output is correct
19 Correct 15 ms 1248 KB Output is correct
20 Correct 2 ms 428 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 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 3 ms 596 KB Output is correct
4 Correct 7 ms 980 KB Output is correct
5 Correct 9 ms 1108 KB Output is correct
6 Correct 7 ms 948 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 8 ms 852 KB Output is correct
9 Correct 14 ms 1524 KB Output is correct
10 Correct 15 ms 1716 KB Output is correct
11 Correct 11 ms 1436 KB Output is correct
12 Correct 10 ms 660 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 12 ms 1532 KB Output is correct
15 Correct 14 ms 1364 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 14 ms 1616 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 15 ms 1816 KB Output is correct
21 Correct 38 ms 4232 KB Output is correct
22 Correct 37 ms 4072 KB Output is correct
23 Correct 16 ms 1620 KB Output is correct
24 Correct 17 ms 2000 KB Output is correct
25 Correct 40 ms 4548 KB Output is correct
26 Correct 16 ms 1620 KB Output is correct
27 Correct 28 ms 3268 KB Output is correct
28 Incorrect 6 ms 2892 KB WA in grader: Too many instructions
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 3196 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 3 ms 688 KB Output is correct
6 Correct 4 ms 692 KB Output is correct
7 Correct 15 ms 1840 KB Output is correct
8 Correct 19 ms 1820 KB Output is correct
9 Correct 28 ms 3188 KB Output is correct
10 Correct 1 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 1 ms 212 KB Output is correct
3 Correct 1 ms 300 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 304 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 304 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 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 300 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 304 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 3 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 432 KB Output is correct
35 Correct 5 ms 428 KB Output is correct
36 Correct 3 ms 428 KB Output is correct
37 Correct 2 ms 340 KB Output is correct
38 Correct 17 ms 2000 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 3 ms 556 KB Output is correct
41 Correct 7 ms 888 KB Output is correct
42 Correct 5 ms 724 KB Output is correct
43 Correct 9 ms 1104 KB Output is correct
44 Correct 24 ms 2064 KB Output is correct
45 Correct 20 ms 2304 KB Output is correct
46 Correct 16 ms 1876 KB Output is correct
47 Correct 8 ms 980 KB Output is correct
48 Correct 2 ms 596 KB Output is correct
49 Correct 13 ms 1616 KB Output is correct
50 Correct 14 ms 1588 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 4 ms 816 KB Output is correct
53 Correct 13 ms 1560 KB Output is correct
54 Correct 12 ms 1404 KB Output is correct
55 Correct 3 ms 596 KB Output is correct
56 Correct 2 ms 596 KB Output is correct
57 Correct 12 ms 1428 KB Output is correct
58 Correct 13 ms 1632 KB Output is correct
59 Correct 13 ms 1616 KB Output is correct
60 Correct 10 ms 1316 KB Output is correct
61 Correct 3 ms 432 KB Output is correct
62 Correct 3 ms 596 KB Output is correct
63 Correct 12 ms 1488 KB Output is correct
64 Correct 16 ms 1616 KB Output is correct
65 Correct 14 ms 1616 KB Output is correct
66 Correct 15 ms 1248 KB Output is correct
67 Correct 2 ms 428 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 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 596 KB Output is correct
73 Correct 7 ms 980 KB Output is correct
74 Correct 9 ms 1108 KB Output is correct
75 Correct 7 ms 948 KB Output is correct
76 Correct 3 ms 468 KB Output is correct
77 Correct 8 ms 852 KB Output is correct
78 Correct 14 ms 1524 KB Output is correct
79 Correct 15 ms 1716 KB Output is correct
80 Correct 11 ms 1436 KB Output is correct
81 Correct 10 ms 660 KB Output is correct
82 Correct 2 ms 596 KB Output is correct
83 Correct 12 ms 1532 KB Output is correct
84 Correct 14 ms 1364 KB Output is correct
85 Correct 2 ms 468 KB Output is correct
86 Correct 3 ms 596 KB Output is correct
87 Correct 14 ms 1616 KB Output is correct
88 Correct 2 ms 468 KB Output is correct
89 Correct 15 ms 1816 KB Output is correct
90 Correct 38 ms 4232 KB Output is correct
91 Correct 37 ms 4072 KB Output is correct
92 Correct 16 ms 1620 KB Output is correct
93 Correct 17 ms 2000 KB Output is correct
94 Correct 40 ms 4548 KB Output is correct
95 Correct 16 ms 1620 KB Output is correct
96 Correct 28 ms 3268 KB Output is correct
97 Incorrect 6 ms 2892 KB WA in grader: Too many instructions
98 Halted 0 ms 0 KB -