Submission #1041353

#TimeUsernameProblemLanguageResultExecution timeMemory
1041353eitanelbAlice, Bob, and Circuit (APIO23_abc)C++17
12 / 100
80 ms11892 KiB
#include "abc.h" // 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 #include<bits/stdc++.h> using namespace std; #define pi pair<int,int> #define x first #define y second void write_num(bool * p, int num){ for(int i=0;i<16;i++){ p[i] = num&1; num>>=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; write_num(outputs_alice, numbers[0]); //outputs_alice[1] = 0; return 16; } // Bob int // returns lb bob( /* in */ const int m, /* in */ const char senders[][5], /* in */ const char recipients[][5], /* out */ bool outputs_bob[] ) { //outputs_bob[0] = 1; //outputs_bob[1] = 1; //outputs_bob[2] = 0; return m; } int * gate_op; //auto gate_opnds; int e; pi ha(int a, int b,int gate_opnds[][2]){ int s = e; gate_op[e]=OP_XOR; gate_opnds[e][0]=a; gate_opnds[e][1]=b; e++; int c = e; gate_op[e]=OP_AND; gate_opnds[e][0]=a; gate_opnds[e][1]=b; e++; return {s,c}; } pi fa(int a, int b, int c,int gate_opnds[][2]){ gate_op[e]=OP_XOR; gate_opnds[e][0]=a; gate_opnds[e][1]=b; e++; int s=e; gate_op[e]=OP_XOR; gate_opnds[e][0]=e-1; gate_opnds[e][1]=c; e++; gate_op[e]=OP_AND; gate_opnds[e][0]=a; gate_opnds[e][1]=b; e++; gate_op[e]=OP_AND; gate_opnds[e][0]=e-3; gate_opnds[e][1]=c; e++; int ca = e; gate_op[e]=OP_OR; gate_opnds[e][0]=e-1; gate_opnds[e][1]=e-2; e++; return {s,ca}; } vector<int> add(vector<int> a, vector<int> b, int op[][2]){ vector<int> c(16); pi p = ha(a[0],b[0],op); c[0]=p.x; int u=p.y; for(int i=1;i<16;i++){ p = fa(a[i],b[i],u,op); c[i]=p.x; u=p.y; } return c; } // 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] ) { //auto gate_opnds=operands; gate_op=operations; e = la+lb; int zero=e; operations[e]=0; operands[e][0]=operands[e][1]=0; e++; int one=e; operations[e]=15; operands[e][0]=operands[e][1]=0; e++; vector<int> cur(16,zero); vector<int> num(16); for(int i=0;i<16;i++) num[i]=i; for(int i=0;i<lb;i++){ cur = add(cur,num,operands); } for(int i=0;i<16;i++) outputs_circuit[0][i]=cur[i]; return e; }

Compilation message (stderr)

abc.cpp: In function 'int circuit(int, int, int*, int (*)[2], int (*)[16])':
abc.cpp:111:9: warning: unused variable 'one' [-Wunused-variable]
  111 |     int one=e;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...