This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "abc.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
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[]
) {
int l = 0;
set<string> d;
vector<string> h;
for(int i=0; i<n; i++){
string a="";
for(int j=0; j<5; j++){
if(names[i][j] == '\00'){
break;
}
a.pb(names[i][j]);
}
h.pb(a);
d.insert(a);
}
int ls = 0;
map<string, int> td;
for(auto it: d){
td[it] = ++ls;
}
vector<pii> q;
for(int i=0; i<n; i++){
q.pb({td[h[i]], numbers[i]});
}
sort(q.begin(), q.end());
for(int i=0; i<n; i++){
//cout<<q[i].ff<<' '<<q[i].ss<<'\n';
for(int k=0; k<16; k++){
outputs_alice[l++] = bool((q[i].ss & (1 << k)));
//cout<<bool((q[i].ss & (1 << k)));
}
//cout<<'\n';
}
for(int i=0; i<n; i++){
for(int k=0; k<16; k++){
outputs_alice[l++] = bool((td[h[i]] & (1 << k)));
}
}
//for(int i=0; i<l; i++){
//cout<<outputs_alice[i];
//if(i % 16 == 15) cout<<'\n';
//}
return l;
}
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char senders[][5],
/* in */ const char recipients[][5],
/* out */ bool outputs_bob[]
) {
int l = 0;
set<string> d;
for(int i=0; i<m; i++){
string a="";
for(int j=0; j<5; j++){
if(senders[i][j] == '\00'){
break;
}
a.pb(senders[i][j]);
}
d.insert(a);
}
for(int i=0; i<m; i++){
string a="";
for(int j=0; j<5; j++){
if(recipients[i][j] == '\00'){
break;
}
a.pb(recipients[i][j]);
}
d.insert(a);
}
int ls = 0;
map<string, int> td;
for(auto it: d){
td[it] = ++ls;
}
map<pii, int> q;
for(int i=0; i<m; i++){
q[{td[senders[i]], td[recipients[i]]}] ++;
}
for(int i=1; i<=d.size(); i++){
for(int j=1; j<=d.size(); j++){
for(int k=0; k<16; k++){
outputs_bob[l++] = bool((q[{j, i}] & (1 << k)));
}
}
}
return l;
}
vector<int> ro;
vector<pii> rp;
int add(int l, int cad, int a, int b){
ro.pb(OP_XOR);
ro.pb(OP_AND);
rp.pb({cad, a});
rp.pb({cad, a});
ro.pb(OP_AND);
rp.pb({b, l+1});
ro.pb(OP_XOR);
rp.pb({b, l+1});
ro.pb(OP_OR);
rp.pb({l+3, l+2});
return l + 5;
}
int sum(int l, int a, int b){
ro.pb(OP_ZERO);
rp.pb({0, 0});
vector<int> res;
l++;
for(int i=0; i<16; i++){
l = add(l, l, a + i, b + i);
res.pb(l - 1);
}
for(int i=0; i<16; i++){
ro.pb(OP_X1);
rp.pb({0, res[i]});
l++;
}
return l;
}
int mult(int l, int a, int b){
for(int i=0; i<16; i++){
ro.pb(OP_ZERO);
rp.pb({0, 0});
l++;
}
int ls = l-15;
for(int k=0; k<16; k++){
int s = l + 1;
for(int i=0; i<16; i++){
ro.pb(OP_AND);
rp.pb({a + i, b + k});
l++;
}
l = sum(l, s, ls);
ls = l - 15;
if(k < 15){
l = sum(l, a, a);
a = l - 15;
}
}
return l;
}
// 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]
) {
ro.clear();
rp.clear();
int l = la + lb - 1;
int n = la / 32;
vector<int> res;
int ls = l - 15;
for(int i=0; i<n; i++){
int ls = l + 1;
for(int k=0; k<16; k++){
ro.pb(OP_ZERO);
rp.pb({0, 0});
l++;
}
for(int j=0; j<n; j++){
l = mult(l, 16 * j, la + 16 * n * i + 16 * j);
//cout<<i<<' '<<j<<' ';
//cout<<16 * j<<' '<<la + 16 * n * i + 16 * j<<'\n';
l = sum(l, ls, l-15);
ls = l - 15;
}
res.pb(ls);
}
for(int i=0; i<la + lb; i++){
operations[i] = 0;
operands[i][0] = -1;
operands[i][1] = -1;
}
for(int i=la + lb; i<=l; i++){
operations[i] = ro[i - la - lb];
operands[i][0] = rp[i - la - lb].ff;
operands[i][1] = rp[i - la - lb].ss;
}
for(int k=0; k<n; k++){
int ls = res[k];
for(int i=0; i<16; i++){
outputs_circuit[k][i] = ls + i;
}
}
return l + 1;
}
Compilation message (stderr)
abc.cpp: In function 'int bob(int, const char (*)[5], const char (*)[5], bool*)':
abc.cpp:139:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | for(int i=1; i<=d.size(); i++){
| ~^~~~~~~~~~
abc.cpp:140:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for(int j=1; j<=d.size(); j++){
| ~^~~~~~~~~~
abc.cpp: In function 'int circuit(int, int, int*, int (*)[2], int (*)[16])':
abc.cpp:234:9: warning: unused variable 'ls' [-Wunused-variable]
234 | int ls = l - 15;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |