Submission #1254950

#TimeUsernameProblemLanguageResultExecution timeMemory
1254950fadak-14Migrations (IOI25_migrations)C++20
30 / 100
28 ms456 KiB
//#include "worldmap.h" //#include "triples.h" //#include "festival.h" #include "migrations.h" #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse2") #define ll long long #define db double #define ld long double #define endl '\n' #define eb emplace_back #define em emplace #define pb push_back #define pf push_front #define pp pop_back #define fr first #define sc second #define sz size #define ir insert #define yes cout << "YES" << endl #define no cout << "NO" << endl #define all(x) x.begin() , x.end() #define alice cout << "Alice" << endl #define bob cout << "Bob" << endl #define fo(x , y) for(ll i = x;i < y;i++) #define lli long long int #define pii pair<lli , lli> #define it int using namespace std; //mt19937 rd(time(NULL)); //IOI 2025 problems const ll oo = 1LL << 60; const ll mxn = 10000; const ll mxk = 1000001; const ll md=1000000007; //vector<int> g[mxn]; /* "souvenirs" -> 39 points for now void buy_souvenirs(int N, ll P0) { if(N==2){transaction(P0-1) ;return;} if(N==3){ auto x=transaction(P0-1); if(x.fr.sz()==1){ll vl=P0-1-x.sc; transaction(vl-1);transaction(vl-1);} else{ll vl= (P0-1-x.sc) ; vl+=(2-vl%2)%2;vl/=2; transaction(vl-1);} return; } vector<ll>cn(N,0) , vl(N); vl[0]=P0; for(int i =1;i < N;i++) { auto x =transaction(vl[i-1] - 1) ; for(int y: x.fr) cn[y]++; if(x.fr.sz() ==1) vl[i] = vl[i-1] - 1 -x.sc; else vl[i] = vl[i-1] - 2; } for(int i = 1; i<N;i++) { while(cn[i] <i) { transaction(vl[i]); cn[i]++; } } } */ /* "World Map" -> 72 points for now vector<vector<int>> regulate(vector<vector<int>> board) { int n= board.sz(); int m=board[0].sz() ; int k = max(n,m); vector an=vector(k,vector<int> (k)); for(int i=0;i<n;i++)for(int j = 0;j<m ;j++)an[i][j]=board[i][j]; for(int i=0;i<k;i++){for(int j=0;j<k;j++){ if(!an[i][j]){ if(j>0&&an[i][j-1])an[i][j] =an[i][j-1]; else if(i>0&&an[i-1][j]) an[i][j] =an[i-1][j]; else assert(false); } }} return an; } bool vs[mxn] ; vector<pair<int, bool>> st; void dfs(int v, int pa=-1) { vs[v]=true; for(int u:g[v]) { if(vs[u])continue; st.pb({u,true}); dfs(u,v); st.pb({v,false}); } } vector<vector<int>> create_map(int N, int M , vector<int> A , vector<int> B) { for(int i = 1 ; i <= N ;i++) g[i].clear(); fill(vs,vs + N+1, false) ; for(int i = 0 ;i < M;i++){g[A[i]].pb(B[i]) ;g[B[i]].pb(A[i]);} st=vector<pair<int,bool>>{{1,true}}; dfs(1); vector ans=vector(N*3 +(N-1), vector<int> (N*2)) ; int x= 0; for(auto [v,fi]:st) { if(fi) { for(int j=0;j<3;j++){for(int k = 0; k < N*2;k++)ans[x+j][k]=v;} for(int j =0;j <g[v].sz() ;j++)ans[x+1][j*2] = g[v][j]; x+=3; } else{ for(int k =0;k<N*2;k++)ans[x][k]=v; x++; } } return regulate(ans) ; } */ //"Triple Peaks" , goal -> 50 , result -> 56.29 /*set<tuple<int, int , int>> sn; inline bool works(int i , int j , int k , const vector<int> &H){ int p[3] = {i , j , k}; sort(p , p +3); i = p[0] , j = p[1] , k =p[2]; if(0>i||i >=j || j >=k || k >=H.sz()) return false; if(j-i == H[k] && k - j == H[i]) return false; if(sn.count({i,j,k})) return false; int d[3] = {j - i , k - j , k -i}; int h[3] = {H[i] , H[j] ,H[k]} ; sort(d , d+3); sort(h, h+3); if(d[0]==h[0] && d[1] == h[1] && d[2] == h[2]) {sn.em(i , j , k); return true;} return false; } struct comb{ map<int, int> a; ll operator*(const comb& b)const{ if(a.sz() > b.a.sz()) return b * *this; ll o=0; for(auto [i,v] :a) if(b.a.count(i)) o+=(ll)v*b.a.at(i); return o; } void insert(int v){a[v]++;} void remove(int v) {if(!--a[v]){a.erase(v);}} }; ll count_triples(vector<int> H) { cerr << "count_triples(...)\n"; const int N = H.sz(); ll ct=0; vector<int> xm(N) , xp(N); for(int x = 0 ; x< N ; x++) {xm[x]=x-H[x]; xp[x] =x+H[x];} map<int, comb>lf, rt; for(int i =0 ; i < N;i++)rt[xp[i]].insert(xm[i]); for(int j = 0 ; j < N;j++){ rt[xp[j]].remove(xm[j]); ct += lf[xm[j]] * rt[xp[j]]; lf[xm[j]].insert(xp[j]); } cerr<<"pre-trivial: "<< ct<< endl; for(int i =0 ; i <N;i++){ for(int j :{i + H[i], i-H[i]}){ if(j < 0||j>=N)continue; for(int k :{i+H[j], i-H[j], j+H[j],j-H[j]}) ct+=works(i , j , k , H); } } cerr<< " = "<<ct<<endl; return ct; } vector<int> construct_range(int M , int K) { return {}; }*/ // CF easy problem /* ll n ,m , t; ll c[mxn] , z[mxn] , h[mxn] , f[mxn] , a[mxn]; vector<ll> e[mxn]; void css(ll nd , ll pr = -1) { z[nd] = 1 ; for(auto ch:e[nd]){if(ch!=pr) css(ch,nd) ,z[nd]+=z[ch];} ll mxs = -1; for(auto ch:e[nd]) {if(ch!=pr && z[ch] > mxs) mxs = z[h[nd] =ch];} } void ubdf(ll vl){ if(++f[vl] == m) t += vl; if(f[vl] > m)m = f[t = vl]; } void pch(ll nd , ll pr = -1) { ubdf(c[nd]) ; for(auto ch: e[nd]){if(ch == pr) continue; pch(ch ,nd);} } void fc(ll nd , ll pr =-1, bool ir = false) { if(!h[nd]) { a[nd] = c[nd] ; if(ir) ubdf(c[nd]) ; return; } for(auto ch :e[nd]) {if(ch == pr|| ch == h[nd])continue; fc(ch,nd) ;} if(h[nd])fc(h[nd] , nd , true) ; for(auto ch :e[nd]) {if(ch == pr|| ch == h[nd])continue; pch(ch ,nd);} ubdf(c[nd]); a[nd] = t; if(!ir) {for(ll i = 1 ; i<= n ;i++){f[i] = 0;} m = t = 0;} }*/ /*ll in() { ll a =0; cin >>a ; return a; } struct bs{ ll b[20] ; ll p[20] ; void ins(ll x , ll pp){ for(ll i =19; ~i; i--){ if(x >> i & 1){ ll &k=b[i]; if(!k && (p[i] = pp ,k=x , 1))return; if(p[i] < pp){ pp^=p[i] ^=pp^=p[i]; k^=x^=k^=x; } x^=k; } } } ll qry(ll l) { ll a=0; for(ll i = 19 ; ~i;i--){ if((~a >> i & 1) && p[i] >=l) a ^= b[i]; } return a; } }bs[mxn];*/ // IOI 2025, day 2 // Task 1 : goal -> 50 points , my own result -> 63 /*vector<it> max_coupons(it A , vector<it> P , vector<it> T) { auto comp=[&](it u,it v){ ll cv=1ll*P[u]*T[u]*T[v]+1ll*P[v]*T[v]; ll cu=1ll*P[v]*T[v]*T[u]+1ll*P[u]*T[u]; return cv<cu; }; auto buy=[&](vector<it>& ids){ sort(begin(ids),end(ids),comp); ll hs=A; for(it i:ids){ hs=min((hs-P[i])*T[i],oo); if(hs<0) return hs; } return hs; }; vector<pair<it,it>> a[4]; it n=(it)P.size(); for(it i=0;i<n;i++)a[T[i]-1].pb({P[i],i}); for(it i=0;i<4;i++)sort(begin(a[i]),end(a[i])); vector<ll> s1={0}; for(auto [x,_]:a[0]) s1.pb(s1.back()+x); vector<it> ids(n); iota(begin(ids),end(ids),0); if(buy(ids)>=0)return ids; it bs=-1; vector<it> ans; for(it i=0;i<=min(it(a[1].size()),65);i++) for(it j=0;j<=min(it(a[2].size()),45);j++) for(it k=0;k<=min(it(a[3].size()),35);k++){ vector<it> ids; for(it u=0;u<i;u++)ids.pb(a[1][u].sc); for(it u=0;u<j;u++)ids.pb(a[2][u].sc); for(it u=0;u<k;u++)ids.pb(a[3][u].sc); ll hs=buy(ids); if(hs<0)continue; it u=upper_bound(begin(s1),end(s1),hs)-begin(s1)-1; it szi=(it)ids.size(); if(u+szi>bs){bs=u+szi; ans=ids;for(it q=0;q<u;q++) ans.pb(a[0][q].sc);} } return ans; }*/ //Task 2 : goal -> 40 const it rf[7]={9999,9998,9997,9996,9995,9994,9993}; const it pw[7]={1,4,16,64,256,1024,4096}; vector<it> dep,par; it send_message(it _N,it i,it Pi) { if(i==1) {dep.assign(_N,0); par.assign(_N,0);} par[i]=Pi; dep[i]=dep[par[i]]+1;it res=0; for(it k=0;k<=6;k++){ if(i==::rf[k]) { it bs=-1,id=-1; for(it j=0;j<_N;j++)if(dep[j]>bs){bs=dep[j];id=j;} if(id==i)res=4; else {for(it j=6;j>k;j--)id%=pw[j];res=id/pw[k];} } } return res; } pair<it,it> longest_path(vector<it> S) { it v=-1; for(it k=0;k<=6;k++)if(S[::rf[k]]==4) {v=::rf[k];break;} if(v==-1) { it res=0; for(it k=0;k<=6;k++)res+=pw[k]*S[::rf[k]]; v=res; } return {0,v}; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...