답안 #920303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920303 2024-02-02T12:30:18 Z Pring 앨리스, 밥, 서킷 (APIO23_abc) C++17
54 / 100
74 ms 11556 KB
#include <bits/stdc++.h>
#include "abc.h"

using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

// 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

const int LEN = 16;
// Alice
int // returns la
alice(
    /*  in */ const int n,
    /*  in */ const char names[][5],
    /*  in */ const unsigned short numbers[],
    /* out */ bool outputs_alice[]
) {
    if (n == 1) {
        FOR(i, 0, LEN) outputs_alice[i] = ((numbers[0] >> i) & 1);
        return LEN;
    }
    vector<pair<string, int>> v(n);
    FOR(i, 0, n) v[i] = mp(string(names[i]), i);
    sort(v.begin(), v.end());
    int cnt = 0;
    FOR(i, 0, n) {
        int id = v[i].sc;
        FOR(j, 0, LEN) {
            outputs_alice[cnt] = ((numbers[id] >> j) & 1);
            cnt++;
        }
    }
    FOR(i, 0, n) {
        int id = v[i].sc;
        FOR(j, 0, n) {
            outputs_alice[cnt] = (j == id);
            cnt++;
        }
    }
    return cnt;
}


// Bob
int // returns lb
bob(
    /*  in */ const int m,
    /*  in */ const char senders[][5],
    /*  in */ const char recipients[][5],
    /* out */ bool outputs_bob[]
) {
    set<string> S;
    map<string, int> M;
    bitset<32> b[32];
    FOR(i, 0, m) {
        S.insert(string(senders[i]));
        S.insert(string(recipients[i]));
    }
    int n = S.size();
    if (n == 1) {
        FOR(i, 0, LEN) outputs_bob[i] = ((m >> i) & 1);
        return LEN;
    }
    {
        int cnt = 0;
        for (auto it = S.begin(); it != S.end(); it++) {
            M[*it] = cnt;
            cnt++;
        }
    }
    FOR(i, 0, m) {
        b[M[senders[i]]][M[recipients[i]]] = true;
    }
    int cnt = 0;
    FOR(i, 0, n) {
        FOR(j, 0, n) {
            outputs_bob[cnt] = b[i][j];
            cnt++;
        }
    }
    return cnt;
}


// 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]
) {

    int cnt = la + lb;
    int n = sqrt(lb);

    auto add_op = [&](int input_a, int input_b, int op) {
        operations[cnt] = op;
        operands[cnt][0] = input_a, operands[cnt][1] = input_b;
        return cnt++;
    };

    auto add_ops = [&](int inputs_a, int inputs_b, int op) {
        int pos = cnt;
        FOR(i, 0, LEN) {
            add_op(inputs_a + i, inputs_b + i, op);
        }
        return pos;
    };

    int zero = add_ops(0, 0, OP_ZERO);

    auto LEFT = [&](int inputs, int p, int b, int op) {
        int pos = cnt;
        FOR(i, 0, LEN) {
            if (i < p) add_op(0, 0, OP_ZERO);
            else add_op(inputs + i - p, b, op);
        }
        return pos;
    };

    auto adder = [&](int inputs_a, int inputs_b) {
        int c = zero, c1, c2, g1;
        vector<int> vc, vg;
        FOR(i, 0, LEN) {
            int a = inputs_a + i, b = inputs_b + i;
            c1 = add_op(a, b, OP_AND);
            g1 = add_op(a, b, OP_XOR);
            c2 = add_op(c, g1, OP_AND);
            vc.push_back(c);
            vg.push_back(g1);
            c = add_op(c1, c2, OP_OR);
        }
        int pos = cnt;
        FOR(i, 0, LEN) {
            add_op(vg[i], vc[i], OP_XOR);
        }
        return pos;
    };

    auto muler = [&](int inputs_a, int inputs_b) {
        int now = zero;
        FOR(i, 0, LEN) {
            now = adder(now, LEFT(inputs_a, i, inputs_b + i, OP_AND));
        }
        return now;
    };

    if (la == LEN && lb == LEN) {
        int a = 0, b = LEN;
        int ans = muler(a, b);
        FOR(i, 0, LEN) outputs_circuit[0][i] = ans + i;
        return cnt;
    }
    vector<int> pos(n);
    FOR(i, 0, n) pos[i] = add_ops(0, 0, OP_ZERO);
    FOR(i, 0, n) {
        FOR(j, 0, n) {
            int a = i * LEN;
            int b = la + i * n + j;
            int tmp = LEFT(a, 0, b, OP_AND);
            pos[j] = adder(pos[j], tmp);
        }
    }
    vector<int> ans(n);
    FOR(i, 0, n) ans[i] = add_ops(0, 0, OP_ZERO);
    FOR(i, 0, n) {
        FOR(j, 0, n) {
            int b = n * LEN + i * n + j;
            ans[j] = add_ops(ans[j], LEFT(pos[i], 0, b, OP_AND), OP_OR);
        }
    }
    FOR(i, 0, n) {
        FOR(j, 0, LEN) outputs_circuit[i][j] = ans[i] + j;
    }
    return cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1216 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1216 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1216 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5988 KB Correct!
2 Correct 33 ms 5996 KB Correct!
3 Correct 41 ms 6364 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5988 KB Correct!
2 Correct 33 ms 5996 KB Correct!
3 Correct 41 ms 6364 KB Correct!
4 Correct 43 ms 7344 KB Correct!
5 Correct 51 ms 6432 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5988 KB Correct!
2 Correct 33 ms 5996 KB Correct!
3 Correct 41 ms 6364 KB Correct!
4 Correct 43 ms 7344 KB Correct!
5 Correct 51 ms 6432 KB Correct!
6 Correct 39 ms 5936 KB Correct!
7 Correct 74 ms 11556 KB Correct!
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1216 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
2 Halted 0 ms 0 KB -