Submission #652058

#TimeUsernameProblemLanguageResultExecution timeMemory
652058TimDeeFlight to the Ford (BOI22_communication)C++17
Compilation error
0 ms0 KiB
#include"communication.h" #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; #define forn(i,n) for (int i=0; i<n; ++i) int V[3000000]; int ptr=0; int asz=0; void brut(int x, int n, int v=0, int i=0, int l=0) { if (i>=n) {V[ptr++]=v; return;} int b=(x>>i)&1; brut(x,n,v+(b<<i),i+1,0); if (l==0) brut(x,n,v+((!b)<<i),i+1,1); } vector<int> get_possible(int n) { ll x=0, q=0; forn(i,29) { q=receive(); x+=q<<i; } brut(x,29); vector<int> b; for (int j=0; j<ptr; ++j) { int x=V[j]; if (x>=n) continue; for (ll i=0; i+x<n; i+=1ll<<29) { b.push_back(x); } } sort(b.begin(), b.end()); ptr=0; return b; } vector<int> dequery(vector<int>&a,int bit) { int x=0, q; forn(i,bit) x+=receive()<<i; brut(x,bit); vector<int> b; for (int j=0; j<ptr; ++j) { int x=V[j]; if (x>=a.size()) continue; for (int i=0; i+x<a.size(); i+=(1<<bit)) { b.push_back(a[i+x]); } } sort(b.begin(), b.end()); ptr=0; return b; } pair<int,int> decode(int n) { if (n>3) return{1,1}; vector<int> a=get_possible(n); //for (auto x:a) cout<<x<<' '; cout<<'\n'; a=dequery(a,21); a=dequery(a,15); a=dequery(a,11); a=dequery(a,8); a=dequery(a,6); a=dequery(a,4); a=dequery(a,3); a=dequery(a,4); //for (auto x:a) cout<<x<<' '; cout<<'\n'; a=dequery(a,3); //for (auto x:a) cout<<x<<' '; cout<<'\n'; a=dequery(a,2); //for (auto x:a) cout<<x<<' '; cout<<'\n'; a=dequery(a,2); //for (auto x:a) cout<<x<<' '; cout<<'\n'; if (a.size()==1) return{a[0]+1,a[0]+1}; if (a.size()==2) return{a[0]+1,a[1]+1}; assert(a.size()==3); int q,x=0; q=receive(); x+=q<<0; q=receive(); x+=q<<1; q=receive(); x+=q<<2; q=receive(); x+=q<<3; vector<int> ans; vector<int> A={0,1,5,10,9,8,2,4}; vector<int> B={1,8,9,11,13,3,12,0}; vector<int> C={6,15,2,4,12,3,7,14}; for (auto v:A) if (v==x) ans.push_back(a[0]); for (auto v:B) if (v==x) ans.push_back(a[2]); for (auto v:C) if (v==x) ans.push_back(a[1]); if (ans.size()==1) return {ans[0]+1,ans[0]+1}; return {ans[0]+1,ans[1]+1}; } int Send(int x, int bit) { ll ret=0; forn(i,bit) ret+=send((x>>i)&1)<<i; return ret; } void get_possible(int[]&a,int n, int x) { x=Send(x,29); brut(x,29); vector<int> b; int cnt=0; for (int j=0; j<ptr; ++j) { int x=V[j]; if (x>=n) continue; for (ll i=0; i+x<n; i+=1ll<<29) { b.push_back(x); } } sort(b.begin(), b.end()); ptr=0; forn(i,b.size()) a[asz++]=b[i]; } vector<int> query(vector<int>&a,int x,int bit) { int l=0,r=a.size()-1; while (l<r) { int mid=(l+r+1)>>1; if (a[mid]>x) r=mid-1; else l=mid; } r=Send(r,bit); brut(r,bit); vector<int> b; for (int j=0; j<ptr; ++j) { int x=V[j]; if (x>=a.size()) continue; for (int i=0; i+x<a.size(); i+=(1<<bit)) { b.push_back(a[i+x]); } } sort(b.begin(), b.end()); ptr=0; return b; } void encode(int n, int x) { --x; get_possible(a,n,x); //for (auto x:a) cout<<x<<' '; cout<<'\n'; if (n>3) return; a=query(a,x,21); a=query(a,x,15); a=query(a,x,11); a=query(a,x,8); a=query(a,x,6); a=query(a,x,4); a=query(a,x,3); a=query(a,x,4); //for (auto x:a) cout<<x<<' '; cout<<'\n'; a=query(a,x,3); //for (auto x:a) cout<<x<<' '; cout<<'\n'; a=query(a,x,2); //for (auto x:a) cout<<x<<' '; cout<<'\n'; a=query(a,x,2); //for (auto x:a) cout<<x<<' '; cout<<'\n'; if (a.size()<3) return; assert(a.size()==3); int v=0,b=0;; if (x==a[0]) { b=send(0); v+=b<<0; b=send(0); v+=b<<1; b=send(0); v+=b<<2; b=send(0); v+=b<<3; } else if (x==a[1]) { b=send(0); v+=b<<0; b=send(1); v+=b<<1; b=send(1); v+=b<<2; b=send(0); v+=b<<3; } else { b=send(1); v+=b<<0; b=send(0); v+=b<<1; b=send(0); v+=b<<2; b=send(1); v+=b<<3; } }

Compilation message (stderr)

communication.cpp: In function 'std::vector<int> dequery(std::vector<int>&, int)':
communication.cpp:45:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         if (x>=a.size()) continue;
      |             ~^~~~~~~~~~
communication.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int i=0; i+x<a.size(); i+=(1<<bit)) {
      |                       ~~~^~~~~~~~~
communication.cpp:38:14: warning: unused variable 'q' [-Wunused-variable]
   38 |     int x=0, q;
      |              ^
communication.cpp: At global scope:
communication.cpp:106:24: error: expected ',' or '...' before '&' token
  106 | void get_possible(int[]&a,int n, int x) {
      |                        ^
communication.cpp: In function 'void get_possible(int*)':
communication.cpp:107:5: error: 'x' was not declared in this scope
  107 |     x=Send(x,29);
      |     ^
communication.cpp:113:16: error: 'n' was not declared in this scope
  113 |         if (x>=n) continue;
      |                ^
communication.cpp:114:26: error: 'n' was not declared in this scope
  114 |         for (ll i=0; i+x<n; i+=1ll<<29) {
      |                          ^
communication.cpp:7:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forn(i,n) for (int i=0; i<n; ++i)
......
  120 |  forn(i,b.size()) a[asz++]=b[i];
      |       ~~~~~~~~~~                  
communication.cpp:120:2: note: in expansion of macro 'forn'
  120 |  forn(i,b.size()) a[asz++]=b[i];
      |  ^~~~
communication.cpp:120:19: error: 'a' was not declared in this scope
  120 |  forn(i,b.size()) a[asz++]=b[i];
      |                   ^
communication.cpp:110:9: warning: unused variable 'cnt' [-Wunused-variable]
  110 |     int cnt=0;
      |         ^~~
communication.cpp: In function 'std::vector<int> query(std::vector<int>&, int, int)':
communication.cpp:135:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |   if (x>=a.size()) continue;
      |       ~^~~~~~~~~~
communication.cpp:136:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |   for (int i=0; i+x<a.size(); i+=(1<<bit)) {
      |                 ~~~^~~~~~~~~
communication.cpp: In function 'void encode(int, int)':
communication.cpp:149:18: error: 'a' was not declared in this scope
  149 |     get_possible(a,n,x); //for (auto x:a) cout<<x<<' '; cout<<'\n';
      |                  ^