답안 #246992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246992 2020-07-10T17:17:44 Z stoyan_malinin Vision Program (IOI19_vision) C++14
컴파일 오류
0 ms 0 KB
#include "vision.h"
//#include "grader.cpp"

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

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 n*r + 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 'void init()':
vision.cpp:81:5: error: 'vector' was not declared in this scope
     vector <int> all;
     ^~~~~~
vision.cpp:81:5: note: suggested alternative:
In file included from /usr/include/c++/7/vector:64:0,
                 from vision.h:5,
                 from vision.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:216:11: note:   'std::vector'
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
vision.cpp:81:13: error: expected primary-expression before 'int'
     vector <int> all;
             ^~~
vision.cpp:86:13: error: 'all' was not declared in this scope
             all.push_back(cell2Pos(i, j));
             ^~~
vision.cpp:86:13: note: suggested alternative: 'a64l'
             all.push_back(cell2Pos(i, j));
             ^~~
             a64l
vision.cpp:90:20: error: 'all' was not declared in this scope
     zero = add_and(all);
                    ^~~
vision.cpp:90:20: note: suggested alternative: 'a64l'
     zero = add_and(all);
                    ^~~
                    a64l
vision.cpp: At global scope:
vision.cpp:94:16: error: 'vector' was not declared in this scope
 Number getDiff(vector <int> &v)
                ^~~~~~
vision.cpp:94:16: note: suggested alternative:
In file included from /usr/include/c++/7/vector:64:0,
                 from vision.h:5,
                 from vision.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:216:11: note:   'std::vector'
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
vision.cpp:94:24: error: expected primary-expression before 'int'
 Number getDiff(vector <int> &v)
                        ^~~
vision.cpp:95:1: error: expected ',' or ';' before '{' token
 {
 ^
vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:139:5: error: 'vector' was not declared in this scope
     vector <int> v;
     ^~~~~~
vision.cpp:139:5: note: suggested alternative:
In file included from /usr/include/c++/7/vector:64:0,
                 from vision.h:5,
                 from vision.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:216:11: note:   'std::vector'
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
vision.cpp:139:13: error: expected primary-expression before 'int'
     vector <int> v;
             ^~~
vision.cpp:142:17: error: expected primary-expression before 'int'
         vector <int> ask;
                 ^~~
vision.cpp:143:32: error: 'ask' was not declared in this scope
         for(int j = 0;j<m;j++) ask.push_back(cell2Pos(i, j));
                                ^~~
vision.cpp:145:9: error: 'v' was not declared in this scope
         v.push_back(add_xor(ask));
         ^
vision.cpp:145:29: error: 'ask' was not declared in this scope
         v.push_back(add_xor(ask));
                             ^~~
vision.cpp:147:24: error: 'v' was not declared in this scope
     Number A = getDiff(v);
                        ^
vision.cpp:152:17: error: expected primary-expression before 'int'
         vector <int> ask;
                 ^~~
vision.cpp:153:32: error: 'ask' was not declared in this scope
         for(int i = 0;i<n;i++) ask.push_back(cell2Pos(i, j));
                                ^~~
vision.cpp:155:29: error: 'ask' was not declared in this scope
         v.push_back(add_xor(ask));
                             ^~~
vision.cpp:160:13: error: expected primary-expression before 'int'
     vector <int> requirements;
             ^~~
vision.cpp:164:9: error: 'requirements' was not declared in this scope
         requirements.push_back(add_not(add_xor({val, sum[bit]})));
         ^~~~~~~~~~~~
vision.cpp:167:13: error: 'requirements' was not declared in this scope
     add_and(requirements);
             ^~~~~~~~~~~~