답안 #794714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794714 2023-07-26T19:45:13 Z FEDIKUS 앨리스, 밥, 서킷 (APIO23_abc) C++17
62 / 100
598 ms 487400 KB
#include "abc.h"
#include<bits/stdc++.h>

using namespace std;

// you may find the definitions useful
const int OP_ZERO    = 0;  // f(OP_ZERO,    x0, x1) = 0
const int OP_NOR     = 1;  // f(OP_NOR,     x0, x1) = !(x0 || x1)
const int OP_GREATER = 2;  // f(OP_GREATER, x0, x1) = (x0 > x1)
const int OP_NOT_X1  = 3;  // f(OP_NOT_X1,  x0, x1) = !x1
const int OP_LESS    = 4;  // f(OP_LESS,    x0, x1) = (x0 < x1)
const int OP_NOT_X0  = 5;  // f(OP_NOT_X0,  x0, x1) = !x0
const int OP_XOR     = 6;  // f(OP_XOR,     x0, x1) = (x0 ^ x1)
const int OP_NAND    = 7;  // f(OP_NAND,    x0, x1) = !(x0 && x1)
const int OP_AND     = 8;  // f(OP_AND,     x0, x1) = (x0 && x1)
const int OP_EQUAL   = 9;  // f(OP_EQUAL,   x0, x1) = (x0 == x1)
const int OP_X0      = 10; // f(OP_X0,      x0, x1) = x0
const int OP_GEQ     = 11; // f(OP_GEQ,     x0, x1) = (x0 >= x1)
const int OP_X1      = 12; // f(OP_X1,      x0, x1) = x1
const int OP_LEQ     = 13; // f(OP_LEQ,     x0, x1) = (x0 <= x1)
const int OP_OR      = 14; // f(OP_OR,      x0, x1) = (x0 || x1)
const int OP_ONE     = 15; // f(OP_ONE,     x0, x1) = 1


// Alice
int // returns la
alice(
    /*  in */ const int n,
    /*  in */ const char names[][5],
    /*  in */ const unsigned short numbers[],
    /* out */ bool outputs_alice[]
) {
    vector<string> imena;
    for(int i=0;i<n;i++) imena.push_back(names[i]);
    sort(imena.begin(),imena.end());
    int la=0;
    for(int i=0;i<n;i++){
        int poz=lower_bound(imena.begin(),imena.end(),names[i])-imena.begin();
        for(int j=0;j<5;j++){
            outputs_alice[la++]=((1<<j)&poz)>>j;
        }
        for(int j=0;j<16;j++){
            outputs_alice[la++]=((1<<j)&numbers[i])>>j;
        }
    }
    return la;
}


// Bob
int // returns lb
bob(
    /*  in */ const int m,
    /*  in */ const char senders[][5],
    /*  in */ const char recipients[][5],
    /* out */ bool outputs_bob[]
) {
    vector<string> imena;
    for(int i=0;i<m;i++){
        imena.push_back(senders[i]);
        imena.push_back(recipients[i]);
    }
    sort(imena.begin(),imena.end());
    imena.resize(unique(imena.begin(),imena.end())-imena.begin());

    int lb=0;

    for(int i=0;i<m;i++){
        int ko=lower_bound(imena.begin(),imena.end(),senders[i])-imena.begin();
        int kome=lower_bound(imena.begin(),imena.end(),recipients[i])-imena.begin();
        for(int j=0;j<5;j++){
            outputs_bob[lb++]=((1<<j)&ko)>>j;
        }
        for(int j=0;j<5;j++){
            outputs_bob[lb++]=((1<<j)&kome)>>j;
        }
    }
    return lb;
}

int l=0;

// Circuit
int // returns l
circuit(
    /*  in */ const int la,
    /*  in */ const int lb,
    /* out */ int operations[],
    /* out */ int operands[][2],
    /* out */ int outputs_circuit[][16]
) {

    auto uradi=[&](int a,int b,int op){
        operations[l]=op;
        operands[l][0]=a;
        operands[l][1]=b;
        return l++;
    };
    auto vise=[&](vector<int> a,int op){
        int tren=a[0];
        for(int i=1;i<a.size();i++){
            tren=uradi(tren,a[i],op);
        }
        return tren;
    };
    auto saberi=[&](vector<int> a,vector<int> b)->vector<int>{
        int prenos=uradi(0,0,OP_ZERO);
        vector<int> rez(16);
        for(int i=0;i<16;i++){
            rez[i]=vise({prenos,a[i],b[i]},OP_XOR);
            prenos=uradi(vise({prenos,a[i],b[i]},OP_AND),uradi(vise({prenos,a[i],b[i]},OP_OR),uradi(rez[i],0,OP_NOT_X0),OP_AND),OP_OR);
        }
        return rez;
    };
    auto jednaki=[&](vector<int> a,vector<int> b)->int{
        int tren=uradi(0,0,OP_ONE);
        for(int i=0;i<a.size();i++){
            tren=uradi(tren,uradi(a[i],b[i],OP_EQUAL),OP_AND);
        }
        return tren;
    };

    l=la+lb;

    int n=la/21;
    int m=lb/10;

    vector<vector<int> > res(n,vector<int>(16));
    for(int i=0;i<n;i++){
        for(int j=0;j<16;j++) res[i][j]=uradi(0,0,OP_ZERO);
    }

    vector<vector<int> > ovajovome(n,vector<int>(n));

    for(int i=0;i<n;i++){
        vector<int> prvi; for(int j=i*21;j<i*21+5;j++) prvi.push_back(j);
        for(int j=0;j<n;j++){
            vector<int> drugi; for(int k=j*21;k<j*21+5;k++) drugi.push_back(k);
            ovajovome[i][j]=uradi(0,0,OP_ZERO);
            for(int poruka=0;poruka<m;poruka++){
                vector<int> ko; for(int i=poruka*10;i<poruka*10+5;i++) ko.push_back(la+i);
                vector<int> kome; for(int i=poruka*10+5;i<poruka*10+10;i++) kome.push_back(la+i);
                ovajovome[i][j]=uradi(ovajovome[i][j],uradi(jednaki(prvi,ko),jednaki(drugi,kome),OP_AND),OP_OR);
            }
        }
    }

    for(int i=0;i<n;i++){
        int ko=i;
        for(int kome=0;kome<n;kome++){
            vector<int> vrko; for(int j=0;j<16;j++) vrko.push_back(uradi(ovajovome[ko][kome],i*21+5+j,OP_AND));
            res[kome]=saberi(res[kome],vrko);
        }
 
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<16;j++){
            outputs_circuit[i][j]=res[i][j];
        }
    }
    return l;
}

Compilation message

abc.cpp: In lambda function:
abc.cpp:101:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(int i=1;i<a.size();i++){
      |                     ~^~~~~~~~~
abc.cpp: In lambda function:
abc.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |         for(int i=0;i<a.size();i++){
      |                     ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1256 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1256 KB Correct!
2 Correct 1 ms 1212 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1256 KB Correct!
2 Correct 1 ms 1212 KB Correct!
3 Incorrect 66 ms 8532 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 7824 KB Correct!
2 Correct 247 ms 172384 KB Correct!
3 Correct 323 ms 223020 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 7824 KB Correct!
2 Correct 247 ms 172384 KB Correct!
3 Correct 323 ms 223020 KB Correct!
4 Correct 260 ms 172772 KB Correct!
5 Correct 353 ms 222612 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 7824 KB Correct!
2 Correct 247 ms 172384 KB Correct!
3 Correct 323 ms 223020 KB Correct!
4 Correct 260 ms 172772 KB Correct!
5 Correct 353 ms 222612 KB Correct!
6 Correct 265 ms 181372 KB Correct!
7 Correct 559 ms 390952 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Runtime error 598 ms 487400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 598 ms 487400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1256 KB Correct!
2 Correct 1 ms 1212 KB Correct!
3 Incorrect 66 ms 8532 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
4 Halted 0 ms 0 KB -