Submission #756868

# Submission time Handle Problem Language Result Execution time Memory
756868 2023-06-12T10:44:00 Z doowey Alice, Bob, and Circuit (APIO23_abc) C++17
8 / 100
64 ms 5080 KB
#include "abc.h"
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

// 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 alice(const int n, const char names[][5],const unsigned short numbers[],bool outputs_alice[]) {
    vector<pair<string, int>> nums;
    for(int i = 0 ; i < n; i ++ ){
        nums.push_back(mp(names[i], numbers[i]));
    }
    sort(nums.begin(), nums.end());
    int len = 0;
    for(int i = 0 ; i < n; i ++ ){
        for(int j = 0 ; j < 16; j ++ ){
            if((nums[i].se & (1 << j))){
                outputs_alice[len] = 1;
            }
            else{
                outputs_alice[len] = 0;
            }
            len ++ ;
        }
    }
    return len;
}


// Bob
int bob(const int m, const char senders[][5], const char recipients[][5], bool outputs_bob[]) {
    vector<string> pp;
    for(int i = 0 ; i < m ; i ++ ){
        pp.push_back(senders[i]);
        pp.push_back(recipients[i]);
    }
    sort(pp.begin(), pp.end());
    pp.resize(unique(pp.begin(), pp.end()) - pp.begin());
    int n = pp.size();
    vector<vector<bool>> E(n);
    for(int i = 0 ; i < n ; i ++ ){
        E[i].resize(n);
    }
    int iu, iv;
    for(int i = 0 ; i < m ; i ++ ){
        string u = senders[i];
        string v = recipients[i];
        iu = lower_bound(pp.begin(), pp.end(), u) - pp.begin();
        iv = lower_bound(pp.begin(), pp.end(), v) - pp.begin();
        E[iu][iv] = true;
    }
    int idx = 0;
    for(int j = 0; j < n; j ++) {
        for(int i = 0 ; i <= j ; i ++ ){
            outputs_bob[idx] = E[i][j];
            idx ++ ;
        }
    }
    return idx;
}

int circuit(const int la, const int lb, int operations[],int operands[][2], int outputs_circuit[][16]) {
    int st = la + lb;
    int n = la / 16;
    int add;
    int edge = la;
    vector<vector<int>> E(n);
    for(int i = 0 ; i < n; i ++ ){
        E[i].resize(n);
    }
    for(int j = 0 ; j < n; j ++ ){
        for(int i = 0 ; i <= j; i ++ ){
            E[i][j]=edge;
            edge++;

        }
    }
    int place;
    int n_add;
    for(int j = 0; j < n; j ++ ){
        vector<int> ind;
        for(int bit = 0; bit < 16; bit ++ ){
            place = st;
            st ++ ;
            operations[place] = 0;
            operands[place][0] = operands[place][1] = 0;
            ind.push_back(place);
        }

        for(int bit = 0; bit < 16; bit ++ ){ // do all additions FROM i-th person WITH bit-th bit
            for(int i = 0 ; i <= j ; i ++ ){
                add = st;
                st ++ ;
                operations[add] = 8;
                operands[add][0] = E[i][j];
                operands[add][1] = i * 16 + bit;
                vector<int> nw = ind;
                for(int g = bit; g < 16; g ++ ){
                    place = st;
                    st ++ ;
                    operations[place] = 6;
                    operands[place][0] = ind[g];
                    operands[place][1] = add;
                    nw[g] = place;
                    n_add = st;
                    st ++ ;
                    operations[n_add] = 8;
                    operands[n_add][0] = ind[g];
                    operands[n_add][1] = add;
                    add = n_add;
                }
                ind = nw;
            }
        }
        for(int b = 0; b < 16; b ++ ){
            outputs_circuit[j][b]=ind[b];
        }
    }
    return st;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1192 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1192 KB Correct!
2 Correct 3 ms 1184 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1192 KB Correct!
2 Correct 3 ms 1184 KB Correct!
3 Incorrect 64 ms 5080 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 3696 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 3696 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 3696 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 3884 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 3884 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1192 KB Correct!
2 Correct 3 ms 1184 KB Correct!
3 Incorrect 64 ms 5080 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
4 Halted 0 ms 0 KB -