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;
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
int alice(const int n, const char names[][5], const unsigned short numbers[], bool outputs_alice[])
{
for (int i=0; i<n; i++)
for (int j=0; j<16; j++)
outputs_alice[i*16+j]=numbers[i]&(1<<j);
vector<pair<string, int> > vec;
for (int i=0; i<n; i++)
{
string str;
for (int j=0; j<4; j++)
str+=names[i][j];
vec.push_back({str, i});
}
sort(vec.begin(), vec.end());
for (int i=n*16; i<n*16+n*n; i++)
outputs_alice[i]=0;
for (int i=0; i<vec.size(); i++)
outputs_alice[n*16+n*vec[i].second+i]=1;
return n*16+n*n;
}
int bob(const int m, const char senders[][5], const char recipients[][5], bool outputs_bob[])
{
map<string, int> mp;
for (int i=0; i<m; i++)
{
string str1, str2;
for (int j=0; j<4; j++)
{
str1+=senders[i][j];
str2+=recipients[i][j];
}
mp[str1]=mp[str2]=1;
}
int n=0;
for (auto it=mp.begin(); it!=mp.end(); it++)
mp[it->first]=(n++);
for (int i=0; i<n*n; i++)
outputs_bob[i]=0;
for (int i=0; i<m; i++)
{
string str1, str2;
for (int j=0; j<4; j++)
{
str1+=senders[i][j];
str2+=recipients[i][j];
}
outputs_bob[n*mp[str2]+mp[str1]]=1;
}
return n*n;
}
int circuit(const int la, const int lb, int operations[], int operands[][2], int outputs_circuit[][16])
{
int pos[30][30], newPos[30][30], ind[16], ind2[16], n=sqrt(lb+0.5), cur=la+lb, carry;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
pos[i][j]=n*16+n*n+n*i+j;
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
vector<int> vec;
for (int k=0; k<n; k++)
{
operands[cur][0]=pos[k][j];
operands[cur][1]=n*16+n*i+k;
operations[cur]=OP_AND;
vec.push_back(cur);
cur++;
}
int pre=vec[0];
for (int k=1; k<n; k++)
{
operands[cur][0]=pre;
operands[cur][1]=vec[k];
operations[cur]=OP_OR;
pre=cur;
cur++;
}
newPos[i][j]=pre;
}
}
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
pos[i][j]=newPos[i][j];
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
vector<int> vec;
for (int k=0; k<n; k++)
{
operands[cur][0]=pos[i][k];
operands[cur][1]=n*16+n*j+k;
operations[cur]=OP_AND;
vec.push_back(cur);
cur++;
}
int pre=vec[0];
for (int k=1; k<n; k++)
{
operands[cur][0]=pre;
operands[cur][1]=vec[k];
operations[cur]=OP_OR;
pre=cur;
cur++;
}
newPos[i][j]=pre;
}
}
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
pos[i][j]=newPos[i][j];
for (int u=0; u<n; u++)
{
for (int i=0; i<16; i++)
{
operands[cur][0]=0;
operands[cur][1]=0;
operations[cur]=OP_ZERO;
ind[i]=cur;
cur++;
}
for (int v=0; v<n; v++)
{
for (int i=0; i<16; i++)
{
operands[cur][0]=v*16+i;
operands[cur][1]=pos[u][v];
operations[cur]=OP_AND;
ind2[i]=cur;
cur++;
}
operands[cur][0]=ind[0];
operands[cur][1]=ind2[0];
operations[cur]=OP_XOR;
operands[cur+1][0]=ind[0];
operands[cur+1][1]=ind2[0];
operations[cur+1]=OP_AND;
ind[0]=cur;
carry=cur+1;
cur+=2;
for (int j=1; j<16; j++)
{
operands[cur][0]=ind[j];
operands[cur][1]=ind2[j];
operations[cur]=OP_XOR;
operands[cur+1][0]=cur;
operands[cur+1][1]=carry;
operations[cur+1]=OP_XOR;
operands[cur+2][0]=ind[j];
operands[cur+2][1]=ind2[j];
operations[cur+2]=OP_AND;
operands[cur+3][0]=ind[j];
operands[cur+3][1]=carry;
operations[cur+3]=OP_AND;
operands[cur+4][0]=ind2[j];
operands[cur+4][1]=carry;
operations[cur+4]=OP_AND;
operands[cur+5][0]=cur+2;
operands[cur+5][1]=cur+3;
operations[cur+5]=OP_OR;
operands[cur+6][0]=cur+5;
operands[cur+6][1]=cur+4;
operations[cur+6]=OP_OR;
ind[j]=cur+1;
carry=cur+6;
cur+=7;
}
}
for (int i=0; i<16; i++)
outputs_circuit[u][i]=ind[i];
}
return cur;
}
Compilation message (stderr)
abc.cpp: In function 'int alice(int, const char (*)[5], const short unsigned int*, bool*)':
abc.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::__cxx11::basic_string<char>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i=0; i<vec.size(); i++)
| ~^~~~~~~~~~~
# | 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... |