답안 #246997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246997 2020-07-10T17:24:50 Z stoyan_malinin Vision Program (IOI19_vision) C++14
100 / 100
34 ms 2492 KB
#include "vision.h"
//#include "grader.cpp"

#include<iostream>
#include<cstring>
#include<vector>

using namespace std;

int n, m, k;
const int MAXLog = 15;

int zero, one;

struct Number
{
    int b[20];

    Number()
    {
        for(int bit = 0;bit<MAXLog;bit++)
        {
            this->b[bit] = zero;
        }
    }
    Number(int x)
    {
        for(int bit = 0;bit<MAXLog;bit++)
        {
            this->b[bit] = (((x>>bit)&1)==0?zero:one);
        }
    }

    int getVal()
    {
        int out = 0;
        //for(int bit = 0;bit<MAXLog;bit++) out += memory_cells[ b[bit] ]*(1<<bit);

        return out;
    }

    int &operator [](int ind)
    {
        return b[ind];
    }
};

Number operator +(Number A, Number B)
{
    Number C;
    int toAdd = zero;

    for(int i = 0;i<MAXLog;i++)
    {
        C[i] = add_xor({toAdd, A[i], B[i]});
        toAdd = add_or({add_and({toAdd, A[i]}), add_and({toAdd, B[i]}), add_and({A[i], B[i]})});
    }

    return C;
}

Number operator -(Number A, Number B)
{
    Number C;
    int toRem = zero;

    for(int i = 0;i<MAXLog;i++)
    {
        C[i] = add_xor({toRem, A[i], B[i]});
        toRem = add_or({add_and({toRem, A[i], B[i]}), add_and({add_not(A[i]), add_or({toRem, B[i]})})});
    }

    return C;
}

int cell2Pos(int r, int c)
{
    return r*m + c;
}

void init()
{
    vector <int> all;
    for(int i = 0;i<n;i++)
    {
        for(int j = 0;j<m;j++)
        {
            all.push_back(cell2Pos(i, j));
        }
    }

    zero = add_and(all);
    one = add_or(all);
}

Number getDiff(vector <int> &v)
{
    Number A, B;

    int active = one;
    for(int i = 0;i<v.size();i++)
    {
        int newVal = add_and({active, v[i]});
        for(int bit = 0;bit<8;bit++)
        {
            if(((i>>bit)&1)==1)
            {
                A[bit] = add_or({A[bit], newVal});
            }
        }

        active = add_and({active, add_not(v[i])});
    }

    active = one;
    for(int i = v.size()-1;i>=0;i--)
    {
        int newVal = add_and({active, v[i]});
        for(int bit = 0;bit<8;bit++)
        {
            if(((i>>bit)&1)==1)
            {
                B[bit] = add_or({B[bit], newVal});
            }
        }

        active = add_and({active, add_not(v[i])});
    }

    Number diff = B - A;
    return diff;
}

void construct_network(int H, int W, int K)
{
    n = H;
    m = W;
    k = K;
    init();

    vector <int> v;
    for(int i = 0;i<n;i++)
    {
        vector <int> ask;
        for(int j = 0;j<m;j++) ask.push_back(cell2Pos(i, j));

        v.push_back(add_xor(ask));
    }
    Number A = getDiff(v);

    v.clear();
    for(int j = 0;j<m;j++)
    {
        vector <int> ask;
        for(int i = 0;i<n;i++) ask.push_back(cell2Pos(i, j));

        v.push_back(add_xor(ask));
    }
    Number B = getDiff(v);

    Number sum = A + B;
    vector <int> requirements;
    for(int bit = 0;bit<MAXLog;bit++)
    {
        int val = (((k>>bit)&1)==0?zero:one);
        requirements.push_back(add_not(add_xor({val, sum[bit]})));
    }

    add_and(requirements);
}

Compilation message

vision.cpp: In function 'Number getDiff(std::vector<int>&)':
vision.cpp:101:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<v.size();i++)
                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 10 ms 896 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 8 ms 768 KB Output is correct
42 Correct 8 ms 768 KB Output is correct
43 Correct 10 ms 896 KB Output is correct
44 Correct 10 ms 1024 KB Output is correct
45 Correct 10 ms 896 KB Output is correct
46 Correct 10 ms 1024 KB Output is correct
47 Correct 10 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 6 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 640 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 7 ms 640 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 7 ms 512 KB Output is correct
6 Correct 7 ms 512 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 9 ms 768 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 9 ms 768 KB Output is correct
11 Correct 8 ms 768 KB Output is correct
12 Correct 12 ms 768 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 640 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 15 ms 1584 KB Output is correct
21 Correct 15 ms 1584 KB Output is correct
22 Correct 15 ms 1584 KB Output is correct
23 Correct 16 ms 1584 KB Output is correct
24 Correct 15 ms 1508 KB Output is correct
25 Correct 16 ms 1584 KB Output is correct
26 Correct 16 ms 1584 KB Output is correct
27 Correct 25 ms 2364 KB Output is correct
28 Correct 25 ms 2492 KB Output is correct
29 Correct 24 ms 2356 KB Output is correct
30 Correct 25 ms 2488 KB Output is correct
31 Correct 34 ms 2388 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2364 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 7 ms 640 KB Output is correct
7 Correct 15 ms 1584 KB Output is correct
8 Correct 15 ms 1584 KB Output is correct
9 Correct 24 ms 2396 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 10 ms 896 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 5 ms 512 KB Output is correct
41 Correct 8 ms 768 KB Output is correct
42 Correct 8 ms 768 KB Output is correct
43 Correct 10 ms 896 KB Output is correct
44 Correct 10 ms 1024 KB Output is correct
45 Correct 10 ms 896 KB Output is correct
46 Correct 10 ms 1024 KB Output is correct
47 Correct 10 ms 1024 KB Output is correct
48 Correct 6 ms 640 KB Output is correct
49 Correct 6 ms 640 KB Output is correct
50 Correct 6 ms 640 KB Output is correct
51 Correct 6 ms 640 KB Output is correct
52 Correct 6 ms 640 KB Output is correct
53 Correct 6 ms 640 KB Output is correct
54 Correct 7 ms 640 KB Output is correct
55 Correct 6 ms 640 KB Output is correct
56 Correct 6 ms 640 KB Output is correct
57 Correct 6 ms 640 KB Output is correct
58 Correct 6 ms 640 KB Output is correct
59 Correct 6 ms 640 KB Output is correct
60 Correct 6 ms 640 KB Output is correct
61 Correct 6 ms 640 KB Output is correct
62 Correct 6 ms 640 KB Output is correct
63 Correct 6 ms 640 KB Output is correct
64 Correct 7 ms 640 KB Output is correct
65 Correct 6 ms 768 KB Output is correct
66 Correct 6 ms 640 KB Output is correct
67 Correct 6 ms 640 KB Output is correct
68 Correct 5 ms 384 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 5 ms 384 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 7 ms 640 KB Output is correct
73 Correct 7 ms 512 KB Output is correct
74 Correct 7 ms 512 KB Output is correct
75 Correct 7 ms 512 KB Output is correct
76 Correct 7 ms 512 KB Output is correct
77 Correct 9 ms 768 KB Output is correct
78 Correct 8 ms 768 KB Output is correct
79 Correct 9 ms 768 KB Output is correct
80 Correct 8 ms 768 KB Output is correct
81 Correct 12 ms 768 KB Output is correct
82 Correct 6 ms 640 KB Output is correct
83 Correct 6 ms 640 KB Output is correct
84 Correct 6 ms 640 KB Output is correct
85 Correct 6 ms 640 KB Output is correct
86 Correct 6 ms 640 KB Output is correct
87 Correct 7 ms 640 KB Output is correct
88 Correct 7 ms 640 KB Output is correct
89 Correct 15 ms 1584 KB Output is correct
90 Correct 15 ms 1584 KB Output is correct
91 Correct 15 ms 1584 KB Output is correct
92 Correct 16 ms 1584 KB Output is correct
93 Correct 15 ms 1508 KB Output is correct
94 Correct 16 ms 1584 KB Output is correct
95 Correct 16 ms 1584 KB Output is correct
96 Correct 25 ms 2364 KB Output is correct
97 Correct 25 ms 2492 KB Output is correct
98 Correct 24 ms 2356 KB Output is correct
99 Correct 25 ms 2488 KB Output is correct
100 Correct 34 ms 2388 KB Output is correct
101 Correct 5 ms 384 KB Output is correct
102 Correct 5 ms 384 KB Output is correct
103 Correct 24 ms 2364 KB Output is correct
104 Correct 5 ms 384 KB Output is correct
105 Correct 9 ms 512 KB Output is correct
106 Correct 8 ms 768 KB Output is correct
107 Correct 6 ms 640 KB Output is correct
108 Correct 7 ms 640 KB Output is correct
109 Correct 15 ms 1584 KB Output is correct
110 Correct 15 ms 1584 KB Output is correct
111 Correct 24 ms 2396 KB Output is correct
112 Correct 5 ms 384 KB Output is correct
113 Correct 5 ms 384 KB Output is correct
114 Correct 25 ms 2492 KB Output is correct
115 Correct 6 ms 640 KB Output is correct
116 Correct 6 ms 640 KB Output is correct
117 Correct 15 ms 1584 KB Output is correct
118 Correct 15 ms 1584 KB Output is correct
119 Correct 25 ms 2372 KB Output is correct
120 Correct 25 ms 2492 KB Output is correct
121 Correct 24 ms 2372 KB Output is correct
122 Correct 26 ms 2372 KB Output is correct
123 Correct 25 ms 2356 KB Output is correct
124 Correct 24 ms 2364 KB Output is correct
125 Correct 24 ms 2356 KB Output is correct
126 Correct 24 ms 2484 KB Output is correct
127 Correct 24 ms 2492 KB Output is correct
128 Correct 24 ms 2484 KB Output is correct