Submission #1062441

#TimeUsernameProblemLanguageResultExecution timeMemory
1062441sleepntsheepFlights (JOI22_flights)C++17
Compilation error
0 ms0 KiB
#include "Ali.h" #include <string> #include <cassert> #include <algorithm> #include <vector> using namespace std; using ll = long long; constexpr int BASE=1e9,D=50; struct bigint{ array<ll,D>v{}; bigint(ll x){ v[0]=x;} bigint() {} int cmpr(const bigint &o)const { for(int i=D-1;i>=0;--i)if(v[i]!=o.v[i])return v[i]<o.v[i]?-1:1; return 0; }; const bigint& operator+=(const bigint&o){ ll carry=0; for(int i=0;i<D;++i){ v[i]=(carry+o.v[i]+v[i]); carry=v[i]/BASE; v[i]%=BASE; } return *this; } const bigint& operator-=(const bigint&o){ for(int i=0;i<D;++i){ v[i]=(v[i]-o.v[i]); if(v[i]<0)v[i]+=BASE,v[i+1]--; } return*this; } const bigint& operator*=(ll x){ ll carry=0; for(int i=0;i<D;++i){ v[i]=(v[i]*x); carry=v[i]/BASE; v[i]%=BASE; } return *this; } friend bigint operator+(bigint&lhs,bigint&rhs){return lhs+=rhs;} friend bigint operator-(bigint&lhs,bigint&rhs){return lhs-=rhs;} friend bigint operator*(bigint&lhs,ll rhs){return lhs*=rhs;} bool operator<(const bigint &o)const{return cmpr(o)==-1;} bool operator>(const bigint &o)const{return cmpr(o)==1;} bool operator>=(const bigint &o)const{return cmpr(o)>=0;} bool operator<=(const bigint &o)const{return cmpr(o)<=0;} bool operator==(const bigint &o)const{return cmpr(o)==0;} }; namespace { const int N=30000; std::vector<int> g[N]; int hld[N],par[N],sz[N],dep[N]; void dfs(int u,int p){ dep[u]=dep[par[u]=p]+1;int best=0; sz[u]=1;for(auto &v:g[u])if(v-p){ dfs(v,u),sz[u]+=sz[v]; if(sz[v]>best)swap(v,g[u][0]),best=sz[v]; } } void efs(int u){ for(auto v:g[u])if(v-par[u]) hld[v]=(v==g[u][0])?hld[u]:v,efs(v); } int lca(int u,int v){ while(hld[u]-hld[v]){ if(dep[hld[u]]<dep[hld[v]])swap(u,v); u=par[hld[u]]; } return dep[u]<dep[v]?u:v; } int dist(int u,int v){return dep[u]+dep[v]-2*dep[lca(u,v)];} void write(string&s,int i,int x,int b=14){ for(int j=0;j<b;++j) s[i+j]=((x>>j)&1)+'0'; } ll read(string&s,int i,int b=14){ int z=0; for(int j=0;j<b;++j)z|=((s[i+j]-'0'))<<j; return z; } int nn; ll valid_enc(ll enc){ return enc/10000<nn and enc%10000<nn; } ll XX(ll enc){return enc/10000;} ll YY(ll enc){return enc%10000;} const int B2=1210; bigint pw2[3000]; bigint npow[4000];int inited; string to_string(bigint &b){ string T; for(int i=B2-1;i>=0;--i) if(b<pw2[i]) T+='0'; else T+='1',b-=pw2[i]; return T; } bigint from_string(string &T){ bigint b; for(int i=0;i<(int)T.size();++i)if(T[i]=='1')b+=pw2[i]; return b; } void init(){ if(inited)return; inited=1; npow[0]=1; for(int i=1;i<4000;++i) npow[i]=npow[i-1]*10000; pw2[0]=1;for(int i=1;i<B2;++i)pw2[i]=pw2[i-1]*2; } } void Init(int N, std::vector<int> U, std::vector<int> V) { init(); ::nn = N; for(int i=0;i<N;++i)g[i].clear(),hld[i]=0,par[i]=0,sz[i]=0,dep[i]=0; for(int i=0;i+1<N;++i)g[U[i]].push_back(V[i]),g[V[i]].push_back(U[i]); for(int i=0;i<N;++i)SetID(i,i); dfs(0,0); hld[0]=0;efs(0); } std::string SendA(std::string S) { init(); ll enc=read(S,0,20); vector<int>dis; for(ll j=0;j<(1<<7);++j){ ll enc2 = (enc&((1<<20)-1)) | (j<<20); if(valid_enc(enc2))dis.push_back(dist(XX(enc2),YY(enc2))); } bigint b; for(int i=0;i<(int)dis.size();++i)b+=npow[i]*dis[i]; return to_string(b); }
#include "Benjamin.h" #include <string> #include <vector> using namespace std; using ll = long long; constexpr int BASE=1e9,D=50; struct bigint{ array<ll,D>v{}; bigint(ll x){ v[0]=x;} bigint() {} int cmpr(const bigint &o)const { for(int i=D-1;i>=0;--i)if(v[i]!=o.v[i])return v[i]<o.v[i]?-1:1; return 0; }; const bigint& operator+=(const bigint&o){ ll carry=0; for(int i=0;i<D;++i){ v[i]=(carry+o.v[i]+v[i]); carry=v[i]/BASE; v[i]%=BASE; } return *this; } const bigint& operator-=(const bigint&o){ for(int i=0;i<D;++i){ v[i]=(v[i]-o.v[i]); if(v[i]<0)v[i]+=BASE,v[i+1]--; } return*this; } const bigint& operator*=(ll x){ ll carry=0; for(int i=0;i<D;++i){ v[i]=(v[i]*x); carry=v[i]/BASE; v[i]%=BASE; } return *this; } friend bigint operator+(bigint&lhs,bigint&rhs){return lhs+=rhs;} friend bigint operator-(bigint&lhs,bigint&rhs){return lhs-=rhs;} friend bigint operator*(bigint&lhs,ll rhs){return lhs*=rhs;} bool operator<(const bigint &o)const{return cmpr(o)==-1;} bool operator>(const bigint &o)const{return cmpr(o)==1;} bool operator>=(const bigint &o)const{return cmpr(o)>=0;} bool operator<=(const bigint &o)const{return cmpr(o)<=0;} bool operator==(const bigint &o)const{return cmpr(o)==0;} }; namespace { int yy,nn; ll enc_; ll XX(ll enc){return enc/10000;} ll YY(ll enc){return enc%10000;} ll valid_enc(ll enc){ return enc/10000<nn and enc%10000<nn; } const int B2=1346; bigint pw2[3000]; bigint npow[4000];int inited; string to_string(bigint &b){ string T; for(int i=B2-1;i>=0;--i) if(b<pw2[i]) T+='0'; else T+='1',b-=pw2[i]; return T; } bigint from_string(string &T){ bigint b; for(int i=0;i<(int)T.size();++i)if(T[i]=='1')b+=pw2[i]; return b; } void init(){ if(inited)return; inited=1; npow[0]=1; for(int i=1;i<4000;++i) npow[i]=npow[i-1]*10000; pw2[0]=1;for(int i=1;i<B2;++i)pw2[i]=pw2[i-1]*2; } } std::string SendB(int N, int X, int Y) { init(); ::nn=N; string S(20,'0'); ll enc=10000ll*X+Y; for(ll j=0;j<20;++j) S[j]=((enc>>j)&1)+'0'; yy=Y; enc_=enc; return S; } int Answer(std::string T) { init(); bigint b=from_string(T); vector<int>dis(100); for(int i=94;i>=0;--i){ int lb=0,ub=10000; while(ub-lb>1){ int md=lb+(ub-lb)/2; if(npow[i]*md>b) ub=md; else lb=md; } dis.push_back(ub-1); b-=npow[i]*(ub-1); } reverse(dis.begin(),dis.end()); int cnt=0; for(ll j=0;j<(1<<7);++j){ ll enc2 = (enc_&((1<<20)-1)) | (j<<20); if(enc2 == enc_) return dis[cnt]; if(valid_enc(enc2))++cnt; } __builtin_unreachable(); }

Compilation message (stderr)

Ali.cpp: In member function 'const bigint& bigint::operator*=(ll)':
Ali.cpp:35:8: warning: variable 'carry' set but not used [-Wunused-but-set-variable]
   35 |     ll carry=0;
      |        ^~~~~
Ali.cpp: At global scope:
Ali.cpp:83:10: warning: 'bigint {anonymous}::from_string(std::string&)' defined but not used [-Wunused-function]
   83 |   bigint from_string(string &T){ bigint b; for(int i=0;i<(int)T.size();++i)if(T[i]=='1')b+=pw2[i]; return b; }
      |          ^~~~~~~~~~~
Ali.cpp:71:8: warning: 'void {anonymous}::write(std::string&, int, int, int)' defined but not used [-Wunused-function]
   71 |   void write(string&s,int i,int x,int b=14){ for(int j=0;j<b;++j) s[i+j]=((x>>j)&1)+'0'; }
      |        ^~~~~
grader_ali.cpp:10:8: warning: '{anonymous}::_randmem' defined but not used [-Wunused-variable]
   10 |   char _randmem[12379];
      |        ^~~~~~~~

Benjamin.cpp:9:3: error: 'array' does not name a type
    9 |   array<ll,D>v{};
      |   ^~~~~
Benjamin.cpp: In constructor 'bigint::bigint(ll)':
Benjamin.cpp:10:17: error: 'v' was not declared in this scope
   10 |   bigint(ll x){ v[0]=x;}
      |                 ^
Benjamin.cpp: In member function 'int bigint::cmpr(const bigint&) const':
Benjamin.cpp:13:31: error: 'v' was not declared in this scope
   13 |     for(int i=D-1;i>=0;--i)if(v[i]!=o.v[i])return v[i]<o.v[i]?-1:1;
      |                               ^
Benjamin.cpp:13:39: error: 'const struct bigint' has no member named 'v'
   13 |     for(int i=D-1;i>=0;--i)if(v[i]!=o.v[i])return v[i]<o.v[i]?-1:1;
      |                                       ^
Benjamin.cpp:13:58: error: 'const struct bigint' has no member named 'v'
   13 |     for(int i=D-1;i>=0;--i)if(v[i]!=o.v[i])return v[i]<o.v[i]?-1:1;
      |                                                          ^
Benjamin.cpp: In member function 'const bigint& bigint::operator+=(const bigint&)':
Benjamin.cpp:19:7: error: 'v' was not declared in this scope
   19 |       v[i]=(carry+o.v[i]+v[i]);
      |       ^
Benjamin.cpp:19:21: error: 'const struct bigint' has no member named 'v'
   19 |       v[i]=(carry+o.v[i]+v[i]);
      |                     ^
Benjamin.cpp: In member function 'const bigint& bigint::operator-=(const bigint&)':
Benjamin.cpp:27:7: error: 'v' was not declared in this scope
   27 |       v[i]=(v[i]-o.v[i]);
      |       ^
Benjamin.cpp:27:20: error: 'const struct bigint' has no member named 'v'
   27 |       v[i]=(v[i]-o.v[i]);
      |                    ^
Benjamin.cpp: In member function 'const bigint& bigint::operator*=(ll)':
Benjamin.cpp:35:7: error: 'v' was not declared in this scope
   35 |       v[i]=(v[i]*x);
      |       ^
Benjamin.cpp: In function 'int Answer(std::string)':
Benjamin.cpp:93:3: error: 'reverse' was not declared in this scope
   93 |   reverse(dis.begin(),dis.end());
      |   ^~~~~~~
Benjamin.cpp: At global scope:
Benjamin.cpp:62:10: warning: 'std::string {anonymous}::to_string(bigint&)' defined but not used [-Wunused-function]
   62 |   string to_string(bigint &b){ string T; for(int i=B2-1;i>=0;--i) if(b<pw2[i]) T+='0'; else T+='1',b-=pw2[i]; return T; }
      |          ^~~~~~~~~
Benjamin.cpp:56:6: warning: 'll {anonymous}::YY(ll)' defined but not used [-Wunused-function]
   56 |   ll YY(ll enc){return enc%10000;}
      |      ^~
Benjamin.cpp:55:6: warning: 'll {anonymous}::XX(ll)' defined but not used [-Wunused-function]
   55 |   ll XX(ll enc){return enc/10000;}
      |      ^~