Submission #769673

#TimeUsernameProblemLanguageResultExecution timeMemory
769673PlurmAlice, Bob, and Circuit (APIO23_abc)C++17
12 / 100
135 ms14364 KiB
#include "abc.h" #include <bits/stdc++.h> 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 vector<tuple<int, int, int>> & operator+=(vector<tuple<int, int, int>> &x, const vector<tuple<int, int, int>> &y) { for (auto p : y) x.push_back(p); return x; } vector<tuple<int, int, int>> adder(int i1, int i2, int offs) { // 16-bit-adder from i1..i1+15 and i2..i2+15 vector<tuple<int, int, int>> ret; ret.push_back({OP_AND, i1, i2}); // offs ret.push_back({OP_XOR, i1, i2}); // offs+1 for (int j = 1; j < 16; j++) { int c = offs + 2 + 8 * (j - 1); int carry = j == 1 ? offs : c - 1; ret.push_back({OP_XOR, i1 + j, i2 + j}); // c ret.push_back({OP_XOR, carry, c}); // c+1 ret.push_back({OP_OR, i1 + j, i2 + j}); // c+2 ret.push_back({OP_NOR, carry, c + 2}); // c+3 ret.push_back({OP_AND, i1 + j, i2 + j}); // c+4 ret.push_back({OP_AND, carry, c + 4}); // c+5 ret.push_back({OP_NOR, c + 1, c + 3}); // c+6 ret.push_back({OP_OR, c + 5, c + 6}); // c+7 // (c+1, c+7): (output, carry) } ret.push_back({OP_OR, offs + 1, offs + 1}); for (int j = 1; j < 16; j++) { ret.push_back({OP_OR, offs + 3 + 8 * (j - 1), offs + 3 + 8 * (j - 1)}); } return ret; // the last 16 bits is the result } vector<tuple<int, int, int>> multiplier(int i1, int i2, int offs) { vector<tuple<int, int, int>> ret; int last = i2; for (int j = 1; j < 16; j++) { ret += adder(last, last, offs + 138 * (j - 1)); last = offs + 138 * j - 16; } // i2, offs + 138*j - 16 int start = offs + 138 * 15; for (int k = 0; k < 16; k++) ret.push_back({OP_AND, i1, i2 + k}); for (int j = 1; j < 16; j++) for (int k = 0; k < 16; k++) ret.push_back({OP_AND, i1 + j, offs + 138 * j - 16 + k}); int stop = start + 256; ret += adder(start, start + 16, stop); for (int j = 2; j < 16; j++) { ret += adder(stop + 138 * (j - 1) - 16, start + 16 * j, stop + 138 * (j - 1)); } // result: offs + 138*15 + 256 + 138*15 - 16 return ret; // the last 16 bits is the result } // 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 < n; i++) { for (int j = 0; j < 16; j++) { outputs_alice[16 * i + j] = (numbers[i] & (1 << j)) ? 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[]) { for (int j = 0; j < 16; j++) outputs_bob[j] = (m & (1 << j)) ? 1 : 0; 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]) { vector<tuple<int, int, int>> mult = multiplier(0, la, la + lb); for (int i = 0; i < mult.size(); i++) { operations[la + lb + i] = get<0>(mult[i]); operands[la + lb + i][0] = get<1>(mult[i]); operands[la + lb + i][1] = get<2>(mult[i]); } for (int i = 0; i < la / 16; ++i) for (int j = 0; j < 16; ++j) outputs_circuit[i][j] = la + lb + mult.size() - 16 + j; return la + lb + mult.size(); }

Compilation message (stderr)

abc.cpp: In function 'int circuit(int, int, int*, int (*)[2], int (*)[16])':
abc.cpp:116:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |     for (int i = 0; i < mult.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
#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...