Submission #897266

#TimeUsernameProblemLanguageResultExecution timeMemory
897266alexander707070Flights (JOI22_flights)C++17
15 / 100
361 ms4796 KiB
#include<bits/stdc++.h> #include "Ali.h" #define MAXN 10007 using namespace std; namespace{ int n,xx,yy,k,root; const int bucket=10; vector<int> v[MAXN]; int dist[MAXN],where[MAXN],num[MAXN],cnt[MAXN]; int l,r,mins,currdist; vector<int> code[MAXN],nodes[MAXN]; void reset(){ k=0; mins=n+1; for(int i=0;i<n;i++){ v[i].clear(); code[i].clear(); cnt[i]=0; } } vector<int> dfs(int x,int p){ vector<int> comp={x},curr; for(int i=0;i<v[x].size();i++){ if(v[x][i]==p)continue; curr=dfs(v[x][i],x); for(int f:curr)comp.push_back(f); } if(comp.size()>=bucket or p==-1){ for(int f:comp)where[f]=k; nodes[k]=comp; k++; comp.clear(); } return comp; } void dfs2(int x,int p){ num[x]=where[x]*(2*bucket-1)+cnt[where[x]]; SetID(x,num[x]); cnt[where[x]]++; for(int i=0;i<v[x].size();i++){ if(v[x][i]==p)continue; if(where[x]==where[v[x][i]]){ code[where[x]].push_back(0); } dfs2(v[x][i],x); } if(p!=-1 and where[x]==where[p]){ code[where[x]].push_back(1); } } void dfs3(int x,int p,int d){ dist[x]=d; for(int i=0;i<v[x].size();i++){ if(v[x][i]==p)continue; dfs3(v[x][i],x,d+1); } } } void Init(int N, vector<int> U, vector<int> V){ n=N; reset(); for(int i=0;i<n-1;i++){ v[U[i]].push_back(V[i]); v[V[i]].push_back(U[i]); } for(int i=0;i<n;i++){ if(v[i].size()<3)root=i; } dfs(root,-1); dfs2(root,-1); } string SendA(string S){ xx=yy=0; for(int i=0;i<10;i++){ xx*=2; if(S[i]=='1')xx++; } for(int i=0;i<10;i++){ yy*=2; if(S[10+i]=='1')yy++; } for(int i:nodes[xx]){ dfs3(i,-1,0); currdist=n; for(int f:nodes[yy]){ currdist=min(currdist,dist[f]); } if(currdist<mins){ mins=currdist; l=i; for(int f:nodes[yy]){ if(dist[f]==mins)r=f; } } } l=num[l]%(2*bucket-1); r=num[r]%(2*bucket-1); string res=""; for(int i=0;i<36;i++){ if(i<code[xx].size())res.push_back(code[xx][i]+'0'); else res+="1"; } for(int i=3;i>=0;i--){ if(((1<<i)&l)==0)res.push_back('0'); else res.push_back('1'); } for(int i=0;i<36;i++){ if(i<code[yy].size())res.push_back(code[yy][i]+'0'); else res.push_back('1'); } for(int i=3;i>=0;i--){ if(((1<<i)&r)==0)res.push_back('0'); else res.push_back('1'); } for(int i=13;i>=0;i--){ if(((1<<i)&mins)==0)res.push_back('0'); else res.push_back('1'); } return res; }
#include<bits/stdc++.h> #include "Benjamin.h" #define MAXN 10007 using namespace std; namespace{ int nn,from,to,s,pos,dis,ld,rd,pt,nd; vector<int> codel,coder; vector<int> treel[30],treer[30]; int dst[30],as,bs; const int del=19; void resets(){ codel.clear(); coder.clear(); for(int i=0;i<30;i++){ treel[i].clear(); treer[i].clear(); } } void dfs4(int x){ while(true){ if(codel[pt]==0){ nd++; pt++; treel[x].push_back(nd); treel[nd].push_back(x); dfs4(nd); }else{ pt++; return; } } } void dfs5(int x){ while(true){ if(coder[pt]==0){ nd++; pt++; treer[x].push_back(nd); treer[nd].push_back(x); dfs5(nd); }else{ pt++; return; } } } void dfs6(int x,int p,int d){ dst[x]=d; for(int i=0;i<treel[x].size();i++){ if(treel[x][i]==p)continue; dfs6(treel[x][i],x,d+1); } } void dfs7(int x,int p,int d){ dst[x]=d; for(int i=0;i<treer[x].size();i++){ if(treer[x][i]==p)continue; dfs7(treer[x][i],x,d+1); } } } string SendB(int N, int X, int Y){ resets(); nn=N; from=X; to=Y; if(from>to)swap(from,to); string res=""; for(int i=9;i>=0;i--){ if(((from/del)&(1<<i))==0)res.push_back('0'); else res.push_back('1'); } for(int i=9;i>=0;i--){ if(((to/del)&(1<<i))==0)res.push_back('0'); else res.push_back('1'); } return res; } int Answer(string T){ pos=ld=rd=0; for(int i=pos;i<pos+36;i++){ codel.push_back(T[i]-'0'); } pos+=36; for(int i=pos;i<pos+4;i++){ ld*=2; if(T[i]=='1')ld++; } pos+=4; nd=pt=0; dfs4(0); if(from/del==to/del){ dfs6(from%del,-1,0); return dst[to%del]; } dfs6(ld,-1,0); as=dst[from%del]; for(int i=pos;i<pos+36;i++){ coder.push_back(T[i]-'0'); } pos+=36; for(int i=pos;i<pos+4;i++){ rd*=2; if(T[i]=='1')rd++; } pos+=4; nd=pt=0; dfs5(0); dfs7(rd,-1,0); bs=dst[to%del]; dis=0; for(int i=pos;i<pos+14;i++){ dis*=2; if(T[i]=='1')dis++; } return as+dis+bs; }

Compilation message (stderr)

Ali.cpp: In function 'std::vector<int> {anonymous}::dfs(int, int)':
Ali.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i=0;i<v[x].size();i++){
      |                     ~^~~~~~~~~~~~
Ali.cpp: In function 'void {anonymous}::dfs2(int, int)':
Ali.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int i=0;i<v[x].size();i++){
      |                     ~^~~~~~~~~~~~
Ali.cpp: In function 'void {anonymous}::dfs3(int, int, int)':
Ali.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for(int i=0;i<v[x].size();i++){
      |                     ~^~~~~~~~~~~~
Ali.cpp: In function 'std::string SendA(std::string)':
Ali.cpp:126:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |         if(i<code[xx].size())res.push_back(code[xx][i]+'0');
      |            ~^~~~~~~~~~~~~~~~
Ali.cpp:136:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |         if(i<code[yy].size())res.push_back(code[yy][i]+'0');
      |            ~^~~~~~~~~~~~~~~~
grader_ali.cpp:10:8: warning: '{anonymous}::_randmem' defined but not used [-Wunused-variable]
   10 |   char _randmem[12379];
      |        ^~~~~~~~

Benjamin.cpp: In function 'void {anonymous}::dfs6(int, int, int)':
Benjamin.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int i=0;i<treel[x].size();i++){
      |                     ~^~~~~~~~~~~~~~~~
Benjamin.cpp: In function 'void {anonymous}::dfs7(int, int, int)':
Benjamin.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for(int i=0;i<treer[x].size();i++){
      |                     ~^~~~~~~~~~~~~~~~
Benjamin.cpp: At global scope:
Benjamin.cpp:8:20: warning: '{anonymous}::s' defined but not used [-Wunused-variable]
    8 |     int nn,from,to,s,pos,dis,ld,rd,pt,nd;
      |                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...