| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 751598 | boyliguanhan | Alice, Bob, and Circuit (APIO23_abc) | C++17 | 0 ms | 0 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "abc.h"
#include<bits/stdc++.h>
using namespace std;
// you may find the definitions useful
const int ZERO    = 0;  // f(ZERO,    x0, x1) = 0
const int NOR     = 1;  // f(NOR,     x0, x1) = !(x0 || x1)
const int GREATER = 2;  // f(GREATER, x0, x1) = (x0 > x1)
const int NOT_X1  = 3;  // f(NOT_X1,  x0, x1) = !x1
const int LESS    = 4;  // f(LESS,    x0, x1) = (x0 < x1)
const int NOT_X0  = 5;  // f(NOT_X0,  x0, x1) = !x0
const int XOR     = 6;  // f(XOR,     x0, x1) = (x0 ^ x1)
const int NAND    = 7;  // f(NAND,    x0, x1) = !(x0 && x1)
const int AND     = 8;  // f(AND,     x0, x1) = (x0 && x1)
const int EQUAL   = 9;  // f(EQUAL,   x0, x1) = (x0 == x1)
const int X0      = 10; // f(X0,      x0, x1) = x0
const int GEQ     = 11; // f(GEQ,     x0, x1) = (x0 >= x1)
const int X1      = 12; // f(X1,      x0, x1) = x1
const int LEQ     = 13; // f(LEQ,     x0, x1) = (x0 <= x1)
const int OR      = 14; // f(OR,      x0, x1) = (x0 || x1)
const int ONE     = 15; // f(ONE,     x0, x1) = 1
#define circ(a,b,c) op1[l] = a, op2[l][0] = b, op2[l][1] = c, l++;
int alices, bobs;
vector<vector<pair<char, int>>> al;
vector<vector<pair<char,char>>> bo;
// Alice
int // returns la
alice(
    /*  in */ const int n,
    /*  in */ const char names[][5],
    /*  in */ const unsigned short numbers[],
    /* out */ bool outputs_alice[]
) {
    for(int j = 0; j < 26; j++)
    for(int i = 0; i < 16; i++)
        outputs_alice[j*16+i] = (bool)(numbers[j]&1<<i);
    map<char[5], int> mp;
    for(int i = 0; i < n; i++)
        mp[names[i]];
    int x = 0;
    for(auto &i: mp)
        i.second = x++;
    int l = 16*26;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 5; j++)
            outputs_alice[l++] = mp[names[i]]&1<<j;
    }
    return l;  
}
// Bob
int // returns lb
bob(
    /*  in */ const int m,
    /*  in */ const char senders[][5],
    /*  in */ const char recipients[][5],
    /* out */ bool outputs_bob[]
) {
    map<char[5], int> mp;
    for(int i = 0; i < m; i++)
        mp[senders[i]], mp[recipients[i]];
    int x = 0;
    for(auto &i: mp)
        i.second = x++;
    int out[26][26]{};
    for(int i = 0; i < m; i++)
        out[mp[recipients[i]]][mp[senders[i]]] = 1;
    for(int i = 0; i < 676; i++)
        outputs_bob[i] = out[i/26][i%26];
    return 676;
}
void xxx(){} // for debug purposes only (like a conditional breakpoint)
void shift(int src, int &l, int op1[], int op2[][2]){
    op1[l] = ZERO, op2[l][0] = 1, op2[l][1] = 2;
    l++;
    for(int i = 0; i < 15; i++)
        circ(X0, src+i,0);
}
int add(int a, int b, int &l, int shifts, int op1[], int op2[][2]) {
    if(!shifts) return a;
    int pos1 = l, pos2 = l+16;
    for(int i = 0; i < 16; i++)
        circ(XOR, a+i, b+i);
    if(l>=241) xxx();
    for(int i = 0; i < 16; i++)
        circ(AND, a+i, b+i);
    if(l>=241) xxx();
    pos2 = l;
    shift(pos2-16, l, op1, op2);
    if(l>=241) xxx();
    return add(pos1, pos2, l, shifts-1, op1, op2);
}
// Circuit
int // returns l
circuit(
    /*  in */ const int la,
    /*  in */ const int lb,
    /* out */ int op1[],
    /* out */ int op2[][2],
    /* out */ int outputs_circuit[][16]
) {
    int l = la+lb, pl = l;
    vector<int> results;
    for(int i = 0; i < 26; i++) {
        for(int j = 0; j < 26; j++)
            for(int k = 0; k < 16; k++)
                circ(AND, la+i*26+j, j*16+k);
        int res = pl;
        for(int j = 1; j < 26; j++)
            res = add(res, pl+j*16, l, 16, op1, op2);
        for(int j = 0; j < 16; j++)
            outputs_circuit[i][j] = res+j;
        pl=l;
    }
    return l;
}
