Submission #814891

# Submission time Handle Problem Language Result Execution time Memory
814891 2023-08-08T10:56:44 Z Hanksburger Alice, Bob, and Circuit (APIO23_abc) C++17
54 / 100
69 ms 9616 KB
#include "abc.h"
#include <bits/stdc++.h>
using namespace std;
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
int alice(const int n, const char names[][5], const unsigned short numbers[], bool outputs_alice[])
{
    for (int i=0; i<n; i++)
        for (int j=0; j<16; j++)
            outputs_alice[i*16+j]=numbers[i]&(1<<j);
    vector<pair<string, int> > vec;
    for (int i=0; i<n; i++)
    {
        string str;
        for (int j=0; j<4; j++)
            str+=names[i][j];
        vec.push_back({str, i});
    }
    sort(vec.begin(), vec.end());
    for (int i=n*16; i<n*16+n*n; i++)
        outputs_alice[i]=0;
    for (int i=0; i<vec.size(); i++)
        outputs_alice[n*16+n*vec[i].second+i]=1;
    return n*16+n*n;
}
int bob(const int m, const char senders[][5], const char recipients[][5], bool outputs_bob[])
{
    map<string, int> mp;
    for (int i=0; i<m; i++)
    {
        string str1, str2;
        for (int j=0; j<4; j++)
        {
            str1+=senders[i][j];
            str2+=recipients[i][j];
        }
        mp[str1]=mp[str2]=1;
    }
    int n=0;
    for (auto it=mp.begin(); it!=mp.end(); it++)
        mp[it->first]=(n++);
    for (int i=0; i<n*n; i++)
        outputs_bob[i]=0;
    for (int i=0; i<m; i++)
    {
        string str1, str2;
        for (int j=0; j<4; j++)
        {
            str1+=senders[i][j];
            str2+=recipients[i][j];
        }
        outputs_bob[n*mp[str2]+mp[str1]]=1;
    }
    return n*n;
}
int circuit(const int la, const int lb, int operations[], int operands[][2], int outputs_circuit[][16])
{
    int pos[30][30], newPos[30][30], ind[16], ind2[16], n=sqrt(lb+0.5), cur=la+lb, carry;
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            pos[i][j]=n*16+n*n+n*i+j;
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            vector<int> vec;
            for (int k=0; k<n; k++)
            {
                operands[cur][0]=pos[k][j];
                operands[cur][1]=n*16+n*i+k;
                operations[cur]=OP_AND;
                vec.push_back(cur);
                cur++;
            }
            int pre=vec[0];
            for (int k=1; k<n; k++)
            {
                operands[cur][0]=pre;
                operands[cur][1]=vec[k];
                operations[cur]=OP_OR;
                pre=cur;
                cur++;
            }
            newPos[i][j]=pre;
        }
    }
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            pos[i][j]=newPos[i][j];
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            vector<int> vec;
            for (int k=0; k<n; k++)
            {
                operands[cur][0]=pos[i][k];
                operands[cur][1]=n*16+n*j+k;
                operations[cur]=OP_AND;
                vec.push_back(cur);
                cur++;
            }
            int pre=vec[0];
            for (int k=1; k<n; k++)
            {
                operands[cur][0]=pre;
                operands[cur][1]=vec[k];
                operations[cur]=OP_OR;
                pre=cur;
                cur++;
            }
            newPos[i][j]=pre;
        }
    }
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            pos[i][j]=newPos[i][j];
    for (int u=0; u<n; u++)
    {
        for (int i=0; i<16; i++)
        {
            operands[cur][0]=0;
            operands[cur][1]=0;
            operations[cur]=OP_ZERO;
            ind[i]=cur;
            cur++;
        }
        for (int v=0; v<n; v++)
        {
            for (int i=0; i<16; i++)
            {
                operands[cur][0]=v*16+i;
                operands[cur][1]=pos[u][v];
                operations[cur]=OP_AND;
                ind2[i]=cur;
                cur++;
            }
            operands[cur][0]=ind[0];
            operands[cur][1]=ind2[0];
            operations[cur]=OP_XOR;

            operands[cur+1][0]=ind[0];
            operands[cur+1][1]=ind2[0];
            operations[cur+1]=OP_AND;

            ind[0]=cur;
            carry=cur+1;
            cur+=2;

            for (int j=1; j<16; j++)
            {
                operands[cur][0]=ind[j];
                operands[cur][1]=ind2[j];
                operations[cur]=OP_XOR;

                operands[cur+1][0]=cur;
                operands[cur+1][1]=carry;
                operations[cur+1]=OP_XOR;

                operands[cur+2][0]=ind[j];
                operands[cur+2][1]=ind2[j];
                operations[cur+2]=OP_AND;

                operands[cur+3][0]=ind[j];
                operands[cur+3][1]=carry;
                operations[cur+3]=OP_AND;

                operands[cur+4][0]=ind2[j];
                operands[cur+4][1]=carry;
                operations[cur+4]=OP_AND;

                operands[cur+5][0]=cur+2;
                operands[cur+5][1]=cur+3;
                operations[cur+5]=OP_OR;

                operands[cur+6][0]=cur+5;
                operands[cur+6][1]=cur+4;
                operations[cur+6]=OP_OR;

                ind[j]=cur+1;
                carry=cur+6;
                cur+=7;
            }
        }
        for (int i=0; i<16; i++)
            outputs_circuit[u][i]=ind[i];
    }
    return cur;
}

Compilation message

abc.cpp: In function 'int alice(int, const char (*)[5], const short unsigned int*, bool*)':
abc.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::__cxx11::basic_string<char>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i=0; i<vec.size(); i++)
      |                   ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1248 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 3 ms 1248 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 3 ms 1248 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 10 ms 5020 KB Correct!
2 Correct 37 ms 6856 KB Correct!
3 Correct 41 ms 7568 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5020 KB Correct!
2 Correct 37 ms 6856 KB Correct!
3 Correct 41 ms 7568 KB Correct!
4 Correct 41 ms 6844 KB Correct!
5 Correct 51 ms 7372 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5020 KB Correct!
2 Correct 37 ms 6856 KB Correct!
3 Correct 41 ms 7568 KB Correct!
4 Correct 41 ms 6844 KB Correct!
5 Correct 51 ms 7372 KB Correct!
6 Correct 39 ms 7664 KB Correct!
7 Correct 69 ms 9616 KB Correct!
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1248 KB WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect.
2 Halted 0 ms 0 KB -