#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
// Alice
int // returns la
alice(
/* in */ const int n,
/* in */ const char names[][5],
/* in */ const unsigned short numbers[],
/* out */ bool outputs_alice[]
) {
vector<string> imena;
for(int i=0;i<n;i++) imena.push_back(names[i]);
sort(imena.begin(),imena.end());
int la=0;
for(int i=0;i<n;i++){
int poz=lower_bound(imena.begin(),imena.end(),names[i])-imena.begin();
for(int j=0;j<5;j++){
outputs_alice[la++]=((1<<j)&poz)>>j;
}
for(int j=0;j<16;j++){
outputs_alice[la++]=((1<<j)&numbers[i])>>j;
}
}
return la;
}
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char senders[][5],
/* in */ const char recipients[][5],
/* out */ bool outputs_bob[]
) {
vector<string> imena;
for(int i=0;i<m;i++){
imena.push_back(senders[i]);
imena.push_back(recipients[i]);
}
sort(imena.begin(),imena.end());
imena.resize(unique(imena.begin(),imena.end())-imena.begin());
int lb=0;
for(int i=0;i<m;i++){
int ko=lower_bound(imena.begin(),imena.end(),senders[i])-imena.begin();
int kome=lower_bound(imena.begin(),imena.end(),recipients[i])-imena.begin();
for(int j=0;j<5;j++){
outputs_bob[lb++]=((1<<j)&ko)>>j;
}
for(int j=0;j<5;j++){
outputs_bob[lb++]=((1<<j)&kome)>>j;
}
}
return lb;
}
int l=0;
// 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]
) {
auto uradi=[&](int a,int b,int op){
operations[l]=op;
operands[l][0]=a;
operands[l][1]=b;
return l++;
};
auto vise=[&](vector<int> a,int op){
int tren=a[0];
for(int i=1;i<a.size();i++){
tren=uradi(tren,a[i],op);
}
return tren;
};
auto saberi=[&](vector<int> a,vector<int> b)->vector<int>{
int prenos=uradi(0,0,OP_ZERO);
vector<int> rez(16);
for(int i=0;i<16;i++){
rez[i]=vise({prenos,a[i],b[i]},OP_XOR);
prenos=uradi(vise({prenos,a[i],b[i]},OP_AND),uradi(vise({prenos,a[i],b[i]},OP_OR),uradi(rez[i],0,OP_NOT_X0),OP_AND),OP_OR);
}
return rez;
};
auto jednaki=[&](vector<int> a,vector<int> b)->int{
int tren=uradi(0,0,OP_ONE);
for(int i=0;i<a.size();i++){
tren=uradi(tren,uradi(a[i],b[i],OP_EQUAL),OP_AND);
}
return tren;
};
l=la+lb;
int n=la/21;
int m=lb/10;
vector<vector<int> > res(n,vector<int>(16));
for(int i=0;i<n;i++){
for(int j=0;j<16;j++) res[i][j]=uradi(0,0,OP_ZERO);
}
vector<vector<int> > ovajovome(n,vector<int>(n));
for(int i=0;i<n;i++){
vector<int> prvi; for(int j=i*21;j<i*21+5;j++) prvi.push_back(j);
vector<int> vr; for(int j=i*21+5;j<i*21+21;j++) vr.push_back(j);
for(int j=0;j<n;j++){
ovajovome[i][j]=uradi(0,0,OP_ZERO);
vector<int> drugi; for(int k=j*21;k<j*21+5;k++) drugi.push_back(k);
for(int poruka=0;poruka<m;poruka++){
vector<int> ko; for(int i=poruka*10;i<poruka*10+5;i++) ko.push_back(la+i);
vector<int> kome; for(int i=poruka*10+5;i<poruka*10+10;i++) kome.push_back(la+i);
ovajovome[i][j]=uradi(ovajovome[i][j],uradi(jednaki(prvi,ko),jednaki(drugi,kome),OP_AND),OP_OR);
}
vector<int> nvr(16);
for(int k=0;k<16;k++) nvr[k]=uradi(vr[k],ovajovome[i][j],OP_AND);
res[j]=saberi(res[j],nvr);
}
}
/*for(int i=0;i<n;i++){
int ko=i;
for(int kome=0;kome<n;kome++){
vector<int> vrko; for(int j=0;j<16;j++) vrko.push_back(uradi(ovajovome[ko][kome],i*21+5+j,OP_AND));
res[kome]=saberi(res[kome],vrko);
}
}*/
for(int i=0;i<n;i++){
for(int j=0;j<16;j++){
outputs_circuit[i][j]=res[i][j];
}
}
return l;
}
Compilation message
abc.cpp: In lambda function:
abc.cpp:101:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i=1;i<a.size();i++){
| ~^~~~~~~~~
abc.cpp: In lambda function:
abc.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1268 KB |
Correct! |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1268 KB |
Correct! |
2 |
Correct |
3 ms |
1080 KB |
Correct! |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1268 KB |
Correct! |
2 |
Correct |
3 ms |
1080 KB |
Correct! |
3 |
Incorrect |
65 ms |
8512 KB |
WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
7712 KB |
Correct! |
2 |
Correct |
259 ms |
172288 KB |
Correct! |
3 |
Correct |
314 ms |
222912 KB |
Correct! |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
7712 KB |
Correct! |
2 |
Correct |
259 ms |
172288 KB |
Correct! |
3 |
Correct |
314 ms |
222912 KB |
Correct! |
4 |
Correct |
263 ms |
172692 KB |
Correct! |
5 |
Correct |
337 ms |
222624 KB |
Correct! |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
7712 KB |
Correct! |
2 |
Correct |
259 ms |
172288 KB |
Correct! |
3 |
Correct |
314 ms |
222912 KB |
Correct! |
4 |
Correct |
263 ms |
172692 KB |
Correct! |
5 |
Correct |
337 ms |
222624 KB |
Correct! |
6 |
Correct |
262 ms |
181324 KB |
Correct! |
7 |
Correct |
548 ms |
391064 KB |
Correct! |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
626 ms |
487392 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
626 ms |
487392 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1268 KB |
Correct! |
2 |
Correct |
3 ms |
1080 KB |
Correct! |
3 |
Incorrect |
65 ms |
8512 KB |
WA Your functions alice(), bob(), circuit() finished successfully, but the final output binary string is incorrect. |
4 |
Halted |
0 ms |
0 KB |
- |