Submission #1308774

#TimeUsernameProblemLanguageResultExecution timeMemory
1308774RaresAliens (IOI16_aliens)C++20
4 / 100
1 ms352 KiB
///acum n*log (maxval) cu aliens trick+cht trick #include <bits/stdc++.h> #include "aliens.h" using namespace std; /**ifstream fin ("date.in"); ofstream fout ("date.out"); #define cin fin #define cout fout**/ const int MAXN=1e5+10; typedef long long ll; ll INF=1e18; int n,m,k; ll dp[MAXN]; int cnt[MAXN]; pair <ll,ll> d[MAXN]; vector <pair <int,int>> aux,v; bool cmp (pair <int,int> a, pair <int,int> b){ if (a.first==b.first) return a.second>b.second; return a.first<b.first; } ll f (pair <ll,ll> d, ll x){ return d.first*x+d.second; } bool g (int i, int j, int x){ ///daca j <= i atunci scot i if (f (d[i],x)>=f (d[j],x)) return true; return false; } ll solve (ll x){ dp[0]=cnt[0]=0; for (int i=1;i<=n;++i){ dp[i]=INF; cnt[i]=1e9; } stack <int> st; for (int i=0;i<=n;++i){ if (i){ dp[i]=v[i].second*v[i].second; if (st.empty ()){ cnt[i]=1; } else{ while (st.size ()>=2){ int i1=st.top (); st.pop (); int i2=st.top (); st.push (i1); if (g (i1,i2,v[i].second)){ st.pop (); } else break; } int pcrt=st.top (); dp[i]+=f (d[pcrt],v[i].second); cnt[i]=cnt[pcrt]+1; } } if (i<=n-1){ ll acrt=-2*(v[i+1].first-1); ll bcrt=dp[i]+1LL*(v[i+1].first-1)*(v[i+1].first-1)+x; ll aux=max (0,v[i].second-v[i+1].first+1); aux*=aux; bcrt-=aux; d[i]={acrt,bcrt}; st.push (i); } } return cnt[n]; } ll take_photos (int N, int M, int K, vector <int> r, vector <int> c){ n=N; m=M; k=K; for (int i=0;i<n;++i){ r[i]++; c[i]++; if (r[i]>c[i]){ swap (r[i],c[i]); } aux.push_back ({r[i],c[i]}); } sort (aux.begin (),aux.end (),cmp); v.push_back ({0,0}); int cmax=0; for (auto x:aux){ if (x.second>cmax){ cmax=x.second; v.push_back (x); } } n=v.size ()-1; ll st=0,dr=1e12,rez; while (st<=dr){ ll mij=(st+dr)/2; if (solve (mij)>k){ st=mij+1; } else{ dr=mij-1; rez=mij; } } solve (rez); return dp[n]-k*rez; }

Compilation message (stderr)

aliens.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...