제출 #1041862

#제출 시각아이디문제언어결과실행 시간메모리
1041862eitanelbAlice, Bob, and Circuit (APIO23_abc)C++17
28 / 100
333 ms481044 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 int rt(int n){ int i=0; while(i*i < n)i++; return i; } 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; for(int i=0;i<n;i++) write_num(outputs_alice+16*i, numbers[i]); //outputs_alice[1] = 0; return 16*n; } // Bob int // returns lb bob( /* in */ const int m, /* in */ const char senders[][5], /* in */ const char recipients[][5], /* out */ bool outputs_bob[] ) { vector<vector<bool>> v(26,vector<bool>(26,0)); for(int i=0;i<m;i++){ v[senders[i][0]-'a'][recipients[i][0]-'a']=1; } for(int i=0;i<26*26;i++){ outputs_bob[i]=v[i/26][i%26]; } return 26*26; } 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; } vector<int> do_and(vector<int> a, vector<int> b, int op[][2]){ vector<int> c(16); for(int i=0;i<16;i++){ c[i]=e; gate_op[e]=OP_AND; op[e][0]=a[i]; op[e][1]=b[i]; e++; } 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++; int n = la/16; for(int i=0;i<n;i++){ vector<int> cur(16,zero); for(int j=0;j<n;j++){ vector<int> mul(16,la + n*j+i); vector<int> numj(16); for(int u=0;u<16;u++) numj[u]=16*j+u; vector<int> to_add = do_and(mul, numj, operands); cur = add(cur,to_add,operands); } for(int j=0;j<16;j++) outputs_circuit[i][j]=cur[j]; } return e; }

컴파일 시 표준 에러 (stderr) 메시지

abc.cpp: In function 'int circuit(int, int, int*, int (*)[2], int (*)[16])':
abc.cpp:126:9: warning: unused variable 'one' [-Wunused-variable]
  126 |     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...