Submission #754103

#TimeUsernameProblemLanguageResultExecution timeMemory
754103TekorAlice, Bob, and Circuit (APIO23_abc)C++17
48 / 100
142 ms49704 KiB
#include "abc.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define f first #define s second #define mp make_pair #define pii pair <int,int> #define all(v) v.begin(),v.end() // 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 const int mod = 65536; int k; // Alice int // returns la alice( /* in */ const int n, /* in */ const char names[][5], /* in */ const unsigned short numbers[], /* out */ bool outputs_alice[] ) { k = 0; vector <pair <string,pii> >g; for(int i = 0;i < n;i++) { g.pb(mp(names[i],mp(numbers[i],i))); } sort(all(g)); for(int i = 0;i < n;i++) { for(int j = 0;j < 16;j++) { if(g[i].s.f & (1 << j))outputs_alice[k++] = 1; else outputs_alice[k++] = 0; } } for(int i = 0;i < n;i++) { int val = g[i].s.s; for(int j = 0;j < 16;j++) { if(val & (1 << j))outputs_alice[k++] = 1; else outputs_alice[k++] = 0; } } return k; } // Bob int // returns lb bob( /* in */ const int m, /* in */ const char senders[][5], /* in */ const char recipients[][5], /* out */ bool outputs_bob[] ) { int c[30][30]; map <string,int> was; int pp = 0; vector <string> g; for(int i = 0;i < m;i++) { g.pb(senders[i]); g.pb(recipients[i]); } sort(all(g)); was[g[0]] = pp++; for(int i = 1;i < g.size();i++) { if(g[i] != g[i - 1])was[g[i]] = pp++; } k = 0; for(int i = 0;i <= 25;i++) { for(int j = 0;j <= 25;j++) { c[i][j] = 0; } } for(int i = 0;i < m;i++) { int num1 = was[senders[i]],num2 = was[recipients[i]]; c[num1][num2]++; } for(int i = 0;i <= 25;i++) { for(int j = 0;j <= 25;j++) { for(int h = 0;h < 16;h++) { if(c[i][j] & (1 << h))outputs_bob[k++] = 1; else outputs_bob[k++] = 0; } } } return k; } vector <int> pos,cur; // 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] ) { k = la + lb; int L = 0,n = la / 32; for(int i = 0;i < n;i++) { pos.pb(k); for(int j = 0;j < 16;j++) { operations[k] = 10; operands[k][0] = L; operands[k][1] = L++; k++; } } for(int i = 0;i < n;i++) { cur.pb(k); for(int j = 0;j < 16;j++) { operations[k] = 0; operands[k][0] = 0; operands[k][1] = 0; k++; } } L += 16 * n; for(int i = 0;i <= 25;i++) { for(int j = 0;j <= 25;j++) { for(int h = 0;h < 16;h++) { for(int pp = 0;pp < 16 - h;pp++) { int nL = k + 16 - (h + pp) + 1; for(int cc = 0;cc < pp + h;cc++) { // = x0 operations[nL + cc] = 10; operands[nL + cc][0] = cur[j] + cc; operands[nL + cc][1] = cur[j] + cc; } // and operations[k] = 8; operands[k][0] = pos[i] + pp; operands[k][1] = L; for(int cc = pp + h;cc < 16;cc++) { //xor operations[nL + cc] = 6; operands[nL + cc][0] = k; operands[nL + cc][1] = cur[j] + cc; k++; operations[k] = 8; operands[k][0] = cur[j] + cc; operands[k][1] = k - 1; } k++; // if(k != nL) { // cout << k << " " << nL; // assert(0); // } k = nL + 16; cur[j] = nL; } L++; } } } vector <int> ans; for(int i = 0;i < n;i++) { ans.pb(k); for(int j = 0;j < 16;j++) { operations[k] = 0; operands[k][0] = 0; operands[k][1] = 0; k++; } } for(int i = 0;i < n;i++) { for(int j = 0;j < n;j++) { int l = 16 * (n + i); operations[k] = 15; operands[k][0] = 0; operands[k][1] = 0; k++; for(int h = 0;h < 16;h++) { if(j & (1 << h)) { operations[k] = 8; operands[k][0] = k - 1; operands[k][1] = l + h; k++; }else { operations[k] = 3; operands[k][0] = l + h; operands[k][1] = l + h; k++; operations[k] = 8; operands[k][0] = k - 1; operands[k][1] = k - 2; k++; } } int last = k - 1; int nL = k + 16; for(int h = 0;h < 16;h++) { operations[k] = 8; operands[k][0] = last; operands[k][1] = cur[i] + h; operations[nL + h] = 6; operands[nL + h][0] = ans[j] + h; operands[nL + h][1] = k; k++; } assert(k == nL); ans[j] = nL; k = nL + 16; } } for(int i = 0;i < n;i++) { for(int j = 0;j < 16;j++) { outputs_circuit[i][j] = ans[i] + j; } } return k; }

Compilation message (stderr)

abc.cpp: In function 'int bob(int, const char (*)[5], const char (*)[5], bool*)':
abc.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |  for(int i = 1;i < g.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...