Submission #981662

# Submission time Handle Problem Language Result Execution time Memory
981662 2024-05-13T12:33:15 Z thelegendary08 Alice, Bob, and Circuit (APIO23_abc) C++17
12 / 100
115 ms 10496 KB
#include "abc.h"
#include<bits/stdc++.h>
#define pb push_back
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define pqpll priority_queue<pair<long long int, long long int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define mii map<int,int>
#define mll map<long long int, long long int>
#define mivi map<int,vector<int>>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
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[]
) {
    outputs_alice[0] = 0;
    outputs_alice[1] = 1;
    f0r(i, 16){
        outputs_alice[i+2] = (numbers[0] & (1<<i));
    }
    return 18;
}

// Bob
int // returns lb
bob(
    /*  in */ const int m,
    /*  in */ const char senders[][5],
    /*  in */ const char recipients[][5],
    /* out */ bool outputs_bob[]
) {
    f0r(i, 16){
        outputs_bob[i] = (m & (1<<i));
    }

    return 16;
}


// 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]
) {
    /*
    operations[5] = 8;
    operations[6] = 14;
    operands[5][0] = 0; operands[5][1] = 4;
    operands[6][0] = 2; operands[6][1] = 5;
    int final_results[] = {20000, 0, 24464};
    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 16; ++j)
            outputs_circuit[i][j] = 5 + (final_results[i] >> j & 1);
    return 7;
    */
    int base = la + lb;
    int cur = la + lb;
    //2~17: n
    //18~33: m
    f0r(i, 16){
        f0r(j, i){
            operations[cur] = OP_AND;
            operands[cur][0] = 0;
            operands[cur][1] = 0;
            cur++;
        }
        f0r(j, 16-i){
            operations[cur] = OP_AND;
            operands[cur][0] = i + 2;
            operands[cur][1] = j + 18;
            cur++;
        }
    }
    f0r(i, 16){
        operations[cur] = OP_AND;
        operands[cur][0] = base + i;
        operands[cur][1] = base + i;
        cur++;
    }

    int d = cur-16;
    f0r(i, 15){
        //lo ~ lo+15 is num
        //d ~ d+15 is running sum
        int lo = (i + 1) * 16 + base;
        //new output starts at d + 16
        int start = d + 16;
        //new running sum: 0, 3, 9, 15, 21, ...
        operations[cur] = OP_XOR;
        operands[cur][0] = lo;
        operands[cur][1] = d;
        cur++;
        operations[cur] = OP_XOR;
        operands[cur][0] = lo+1;
        operands[cur][1] = d+1;
        cur++;
        operations[cur] = OP_AND;
        operands[cur][0] = lo;
        operands[cur][1] = d;
        cur++;
        operations[cur] = OP_XOR;
        operands[cur][0] = d + 16 + 1;
        operands[cur][1] = d + 16 + 2;
        cur++;
        FOR(j, 2, 16){
            operations[cur] = OP_XOR;
            operands[cur][0] = lo + j;
            operands[cur][1] = d + j;
            cur++;
            operations[cur] = OP_OR;
            operands[cur][0] = lo + j - 1;
            operands[cur][1] = d + j - 1;
            cur++;
            operations[cur] = OP_AND;
            operands[cur][0] = cur - 1;
            operands[cur][1] = cur - 4;
            cur++;
            operations[cur] = OP_AND;
            operands[cur][0] = lo + j - 1;
            operands[cur][1] = d + j - 1;
            cur++;
            operations[cur] = OP_OR;
            operands[cur][0] = cur - 1;
            operands[cur][1] = cur - 2;
            cur++;
            operations[cur] = OP_XOR;
            operands[cur][0] = cur - 1;
            operands[cur][1] = cur - 5;
            cur++;
        }
        operations[cur] = OP_AND;
        operands[cur][0] = start;
        operands[cur][1] = start;
        cur++;
        operations[cur] = OP_AND;
        operands[cur][0] = start+3;
        operands[cur][1] = start+3;
        cur++;
        f0r(j, 14){
            operations[cur] = OP_AND;
            operands[cur][0] = start + 9 + j * 6;
            operands[cur][1] = start + 9 + j * 6;
            cur++;
        }

        d = cur - 16;
    }

    for(int j = 0; j < 16; ++j)outputs_circuit[0][j] = d + j;
    return cur;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1292 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1292 KB Correct!
2 Correct 0 ms 1520 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1292 KB Correct!
2 Correct 0 ms 1520 KB Correct!
3 Correct 43 ms 5096 KB Correct!
4 Correct 47 ms 4888 KB Correct!
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1528 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 5 ms 1528 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 5 ms 1528 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 115 ms 10496 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 115 ms 10496 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 Correct 2 ms 1292 KB Correct!
2 Correct 0 ms 1520 KB Correct!
3 Correct 43 ms 5096 KB Correct!
4 Correct 47 ms 4888 KB Correct!
5 Incorrect 5 ms 1528 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
6 Halted 0 ms 0 KB -