Submission #487485

#TimeUsernameProblemLanguageResultExecution timeMemory
487485inksamuraiTenis (COCI20_tenis)C++17
0 / 110
0 ms204 KiB
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() #define rep(i,n) for(int i=0;i<n;i++) #define crep(i,x,n) for(int i=x;i<n;i++) #define drep(i,n) for(int i=n-1;i>=0;i--) #define vec(...) vector<__VA_ARGS__> #define _322ZVFH ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) using namespace std; typedef long long ll; typedef long double ld; using pii=pair<int,int>; using vi=vector<int>; int main(){ _322ZVFH; int n; cin>>n; vec(vi) a(n,vi(3)); rep(j,3)rep(i,n){ int x; cin>>x; x--; a[x][j]=i+1; } auto gwin=[&](int i,int j)->pii{ int mna=1e9,mnab=1e9,ca=-1; rep(t,3){ if(a[i][t]<mna){ mna=a[i][t]; mnab=a[j][t]; ca=t; }else if(a[i][t]==mna){ if(a[j][t]<mnab){ mnab=a[j][t]; ca=t; } } } int mnb=1e9,mnba=1e9,cb=-1; rep(t,3){ if(a[j][t]<mnb){ mnb=a[j][t]; mnba=a[i][t]; cb=t; }else if(a[j][t]==mnb){ if(a[i][t]<mnba){ mnba=a[i][t]; cb=t; } } } pii p={-1,-1}; p=(mna<mnb?pii{mna,mnab}:mnb<mna?pii{mnb,mnba}:mnab<mnba?pii{mna,mnab}:pii{mnb,mnba}); int cnt=0,pans1=-1,pans2=-1; rep(t,3){ if(a[i][t]==p.fi and a[j][t]==p.se){ if(pans1==-1){ pans1=t; pans2=i; } } if(a[j][t]==p.fi and a[i][t]==p.se){ if(pans2==-1){ pans1=t; pans2=j; } } } return {pans1,pans2}; }; vec(vec(vec(vi))) psum(n+10,vec(vec(vi))(3,vec(vi)(3,vi(3,0)))); // val,t,seb/+1,seb/+2 rep(i,n){ rep(t,3){ int t1=(t+1)%3,t2=(t+2)%3; int cond1=0,cond2=0; if(a[i][t]>a[i][t1]) cond1=2; else if(a[i][t]<a[i][t1]) cond1=1; if(a[i][t]>a[i][t2]) cond2=2; else if(a[i][t]<a[i][t2]) cond2=1; psum[*min_element(all(a[i]))][t][cond1][cond2]++; } } rep(t,3){ rep(cond1,3){ rep(cond2,3){ drep(i,n+1){ psum[i][t][cond1][cond2]+=psum[i+1][t][cond1][cond2]; } } } } vi pans(3,0),ppans(n+10,0); rep(i,n){ int minima=*min_element(all(a[i])); int x=minima; int cnt=count(all(a[i]),minima); if(cnt==1){ rep(t,3){ if(a[i][t]==minima){ int now=0; rep(j,3)rep(j1,3){ now+=psum[x+1][t][j][j1]; } pans[t]+=now; ppans[i]+=now; } } }else if(cnt==2){ int t0=-1,t1=-1; rep(t,3){ if(a[i][t]==minima){ if(t0==-1) t0=i; else t1=i; } } assert(t0!=-1 and t1!=-1); int now=0; rep(j,3)rep(j1,3){ if(t1==(t0+1)%3 and j==2) continue; if(t1==(t0+2)%3 and j1==2) continue; now+=psum[x+1][t0][j][j1]; // count for t0 } pans[t0]+=now; ppans[i]+=now; now=0; rep(j,3)rep(j1,3){ if(t0==(t1+1)%3 and j!=1) continue; if(t0==(t1+2)%3 and j1!=1) continue; now+=psum[x+1][t1][j][j1]; // count for t1 } pans[t1]+=now; ppans[i]+=now; }else{ int now=0; rep(j,3)rep(j1,3){ if(j==2 or j1==2) continue; now+=psum[x+1][0][j][j1]; } pans[0]+=now; ppans[i]+=now; now=0; rep(j,3)rep(j1,3){ if(j==2 or j1!=1) continue; now+=psum[x+1][1][j][j1]; } pans[1]+=now; ppans[i]+=now; now=0; rep(j,3)rep(j1,3){ if(j!=1 or j1!=1) continue; now+=psum[x+1][2][j][j1]; } pans[2]+=now; ppans[i]+=now; } } vec(vi) rbts(n+10); rep(i,n){ int x=*min_element(all(a[i])); rbts[x].pb(i); } set<pii> st; crep(minima,1,n+1){ rep(i,sz(rbts[minima])){ crep(j,i+1,sz(rbts[minima])){ int x=rbts[minima][i],y=rbts[minima][j]; if(st.find(minmax(x,y))!=st.end()) continue; st.insert(minmax(x,y)); pii p=gwin(x,y); pans[p.fi]++; ppans[p.se]++; } } } rep(i,n){ rep(j,n){ if(i==j or st.find(minmax(i,j))!=st.end()) continue; st.insert(minmax(i,j)); pii p=gwin(i,j); pans[p.fi]++; ppans[p.se]++; } } // print rabbits { rep(t,3){ cout<<pans[t]<<" "; } cout<<"\n"; rep(i,n){ cout<<ppans[i]<<" "; } cout<<"\n"; } // // return 0; }

Compilation message (stderr)

tenis.cpp: In lambda function:
tenis.cpp:30:24: warning: variable 'ca' set but not used [-Wunused-but-set-variable]
   30 |   int mna=1e9,mnab=1e9,ca=-1;
      |                        ^~
tenis.cpp:43:24: warning: variable 'cb' set but not used [-Wunused-but-set-variable]
   43 |   int mnb=1e9,mnba=1e9,cb=-1;
      |                        ^~
tenis.cpp:58:7: warning: unused variable 'cnt' [-Wunused-variable]
   58 |   int cnt=0,pans1=-1,pans2=-1;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...