Submission #972402

#TimeUsernameProblemLanguageResultExecution timeMemory
972402MarwenElarbiAliens (IOI16_aliens)C++17
60 / 100
521 ms262448 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long const int nax=50005; vector<pair<long long,long long>> v; long long dp[50005][4005]; bool compare(pair<int,int> a,pair<int,int> b){ if(a.fi!=b.fi) return a.fi<b.fi; return a.se>b.se; } void daq(int l,int r,int left,int right,int level){ if(l>r) return; int mid=(r+l)/2; //if(dp[mid][level]<1e18) return; ll opt=0; ll lst=v[mid].se; ll cur=1; //cout <<l<<" "<<r<<" "<<left<<" "<<right<<" "<<mid<<endl; for (int i = min(right,mid); i >= left; --i) { if(i==0){ dp[mid][1]=cur*cur; continue; } cur+=lst-v[i].fi; lst=v[i].fi; long long nabba=dp[i-1][level-1]+cur*cur-1ll*max(1ll*0,v[i-1].se-v[i].fi+1)*max(1ll*0,v[i-1].se-v[i].fi+1); if(dp[mid][level]>nabba){ opt=i; dp[mid][level]=nabba; } //cout <<mid<<" "<<i<<" "<<nabba<<" "<<dp[i-1][level-1]<<" "<<level<<endl; } //cout <<dp[mid][level]<<" "<<opt<<endl; if(l==r) return; daq(l,mid,left,opt,level); daq(mid+1,r,opt,right,level); } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){ pair<int,int> tab[n]; for (int i = 0; i < n; ++i) { tab[i]={min(r[i],c[i]),max(r[i],c[i])}; } sort(tab,tab+n,compare); v.push_back({-1,-1}); for (int i = 0; i < n; ++i) { if(v.empty()) v.push_back(tab[i]); else if(v.back().se>=tab[i].se) continue; else v.push_back(tab[i]); } n=v.size(); for (int i = 0; i < n; ++i) { for (int j = 0; j <= k; ++j) { if(i) dp[i][j]=2e18; else dp[i][j]=0; } } for (int i = 1; i <= k; ++i) { daq(1,n-1,1,n-1,i); } long long ans=1ll*m*m; for (int i = 1; i <= k; ++i) { ans=min(ans,dp[n-1][i]); } return ans; }
#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...