#include <bits/stdc++.h>
#include "communication.h"
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
vector<int> use(vector<int> a,vector<int> b,int x,int t){
sort(a.begin(),a.end());
sort(b.begin(),b.end());
if(a.size()+b.size()<=2){
vector<int> z;
for(auto h:a){
z.push_back(h);
}
for(auto h:b){
z.push_back(h);
}
if(z.size()==1){
z.push_back(z[0]);
}
return z;
}
vector<int> la,ra,lb,rb;
if(a.size()+b.size()==3){
vector<int> g;
for(auto h:a){
g.push_back(h);
}
for(auto h:b){
g.push_back(h);
}
sort(g.begin(),g.end());
int u=-1;
for(int i=0;i<3;i++){
if(g[i]==x){
u=i;
}
}
if(t==0){
return g;
}
else{
string s[3]={"1111","0001","1000"};
if(u==-1){
string z;
for(int j=0;j<4;j++){
z+=char('0'+receive());
}
int flag=-1;
for(int i=0;i<3;i++){
int lst=0;
for(int j=0;j<4;j++){
if(s[i][j]!=z[j]){
if(lst){
flag=i;
break;
}
else{
lst=1;
}
}
else{
lst=0;
}
}
}
assert(flag>=0);
vector<int> ret;
for(int i=0;i<3;i++){
if(i!=flag){
ret.push_back(g[i]);
}
}
return ret;
}
else{
for(int i=0;i<4;i++){
send(int(s[u][i]-'0'));
}
return vector<int>();
}
}
}
int as=a.size(),bs=b.size();
int nxt=-1;
for(int i=0;i<as/2;i++){
if(a[i]==x){
nxt=0;
}
la.push_back(a[i]);
rb.push_back(a[i]);
}
for(int i=as/2;i<as;i++){
if(a[i]==x){
nxt=1;
}
ra.push_back(a[i]);
lb.push_back(a[i]);
}
for(int i=0;i<(bs+1)/2;i++){
if(b[i]==x){
nxt=0;
}
la.push_back(b[i]);
}
for(int i=(bs+1)/2;i<bs;i++){
if(b[i]==x){
nxt=1;
}
ra.push_back(b[i]);
}
int dd;
if(nxt==-1){
dd=receive();
}
else{
dd=send(nxt);
}
if(dd==0){
return use(la,lb,x,t);
}
else{
return use(ra,rb,x,t);
}
}
const int n=1e9+7;
const int B=31647;
void encode(int N,int x){
int a=x/B;
int c=x%B;
vector<int> v(max(3,N/B+1));
iota(v.begin(),v.end(),0);
auto e=use(v,vector<int>(),a,0);
vector<int> w(B);
iota(w.begin(),w.end(),0);
auto f=use(w,vector<int>(),c,0);
assert(e.size()==3 && f.size()==3);
vector<int> z;
for(auto h:e){
for(auto y:f){
if(h*B+y<=0 || h*B+y>N){
continue;
}
z.push_back(h*B+y);
}
}
use(z,vector<int>(),x,1);
}
pair<int,int> decode(int N){
vector<int> v(max(3,N/B+1));
iota(v.begin(),v.end(),0);
auto e=use(v,vector<int>(),-1,0);
vector<int> w(B);
iota(w.begin(),w.end(),0);
auto f=use(w,vector<int>(),-1,0);
assert(e.size()==3 && f.size()==3);
vector<int> z;
for(auto h:e){
for(auto y:f){
if(h*B+y<=0 || h*B+y>N){
continue;
}
z.push_back(h*B+y);
}
}
auto j=use(z,vector<int>(),-1,1);
return {j[0],j[min(1,(int)z.size())]};
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
416 ms |
6704 KB |
Output is correct |
2 |
Correct |
584 ms |
6888 KB |
Output is correct |
3 |
Correct |
814 ms |
6796 KB |
Output is correct |
4 |
Correct |
414 ms |
6700 KB |
Output is correct |
5 |
Correct |
603 ms |
6724 KB |
Output is correct |
6 |
Correct |
1528 ms |
11864 KB |
Output is correct |
7 |
Correct |
3149 ms |
6720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
5293 ms |
7044 KB |
Output is partially correct |
2 |
Partially correct |
3212 ms |
7116 KB |
Output is partially correct |
3 |
Partially correct |
4130 ms |
6968 KB |
Output is partially correct |
4 |
Partially correct |
7274 ms |
7380 KB |
Output is partially correct |
5 |
Partially correct |
6474 ms |
7148 KB |
Output is partially correct |
6 |
Correct |
5564 ms |
7240 KB |
Output is correct |
7 |
Incorrect |
6085 ms |
3216 KB |
Security violation! |
8 |
Halted |
0 ms |
0 KB |
- |