Submission #956074

#TimeUsernameProblemLanguageResultExecution timeMemory
956074pccAlice, Bob, and Circuit (APIO23_abc)C++17
4 / 100
121 ms10096 KiB
#include "abc.h" #include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fs first #define sc second // 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[] ) { for(int i = 0;i<16;i++){ if(numbers[0]&(1<<i))outputs_alice[i] = 1; else outputs_alice[i] = 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[] ) { for(int i = 0;i<10;i++){ if(m&(1<<i))outputs_bob[i] = 1; else outputs_bob[i] = 0; } return 10; } // Circuit int ptr = 0; int ZERO,ONE; function<int(int,int,int)> ADD_OP; function<pii(int,int)> HALF_ADDER; int // returns l circuit( /* in */ const int la, /* in */ const int lb, /* out */ int operations[], /* out */ int operands[][2], /* out */ int outputs_circuit[][16] ) { ptr = la+lb; ADD_OP = [&](int a,int b,int op){ operands[ptr][0] = a,operands[ptr][1] = b,operations[ptr] = op; return ptr++; }; HALF_ADDER = [&](int a,int b){//{val,carry} return pii(ADD_OP(a,b,OP_XOR),ADD_OP(a,b,OP_AND)); }; ZERO = ADD_OP(0,0,OP_ZERO); ONE = ADD_OP(0,0,OP_ONE); struct NUM{ int pos[16]; NUM(){memset(pos,-1,sizeof(pos));} NUM operator+(NUM b)const{ NUM re; int cry = 0; for(int i = 0;i<16;i++){ auto [ta,tb] = HALF_ADDER(pos[i],b.pos[i]); if(!cry){ cry = tb; re.pos[i] = ta; } else{ auto [tc,td] = HALF_ADDER(cry,ta); re.pos[i] = tc; cry = ADD_OP(tb,td,OP_OR); } } re.pos[15] = ADD_OP(ADD_OP(pos[15],b.pos[15],OP_XOR),cry,OP_XOR); return re; } NUM operator*(NUM b)const{//16bit*10bit vector<int> v[16]; for(int i = 0;i<15;i++){ for(int j = 0;j<10;j++){ if(i+j < 16){ v[i+j].push_back(ADD_OP(pos[i],b.pos[j],OP_AND)); } } } NUM re; for(int i = 0;i<15;i++){ if(v[i].empty())re.pos[i] = ZERO; else{ re.pos[i] = v[i][0]; for(int j = 1;j<v[i].size();j++){ auto tmp = HALF_ADDER(v[i][j],re.pos[i]); re.pos[i] = tmp.fs; v[i+1].push_back(tmp.sc); } } } if(v[15].size())re.pos[15] = v[15][0]; else re.pos[15] = ZERO; for(int i = 1;i<v[15].size();i++)re.pos[15] = ADD_OP(re.pos[15],v[15][i],OP_XOR); return re; } }; NUM a,b; for(int i = 0;i<la;i++)a.pos[i] = i; for(int i = 0;i<lb;i++)b.pos[i] = i+la; NUM re = a*b; for(int i = 0;i<16;i++)outputs_circuit[0][i] = re.pos[i]; return ptr; }

Compilation message (stderr)

abc.cpp: In member function 'circuit(int, int, int*, int (*)[2], int (*)[16])::NUM circuit(int, int, int*, int (*)[2], int (*)[16])::NUM::operator*(circuit(int, int, int*, int (*)[2], int (*)[16])::NUM) const':
abc.cpp:122:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |      for(int j = 1;j<v[i].size();j++){
      |                    ~^~~~~~~~~~~~
abc.cpp:131:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |    for(int i = 1;i<v[15].size();i++)re.pos[15] = ADD_OP(re.pos[15],v[15][i],OP_XOR);
      |                  ~^~~~~~~~~~~~~
#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...