제출 #972347

#제출 시각아이디문제언어결과실행 시간메모리
972347MarwenElarbiAliens (IOI16_aliens)C++17
4 / 100
2 ms2652 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second const int nax=50005; vector<pair<int,int>> v; long long dp[nax][105]; 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; int opt=0; int lst=v[mid].se; int 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-max(0,v[i-1].se-v[i].fi+1)*max(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(); long long cur=1; long long lst=v[1].fi; for (int i = 0; i < n; ++i) { if(i>0){ cur+=v[i].se-lst; //cout<<lst<<" "<<cur<<endl; lst=v[i].se; dp[i][1]=cur*cur; } for (int j = 0; j <= k; ++j) { if(j>1) dp[i][j]=1e18; else if(!j) dp[i][j]=0; } } for (int i = 2; i <= k; ++i) { daq(1,n-1,0,n-1,i); } long long ans=m*m; for (int i = 1; i <= k; ++i) { ans=min(ans,dp[n-1][i]); } return ans; } /*int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, m, k; assert(3 == scanf("%d %d %d", &n, &m, &k)); std::vector<int> r(n), c(n); for (int i = 0; i < n; i++) { assert(2 == scanf("%d %d", &r[i], &c[i])); } long long ans = take_photos(n, m, k, r, c); printf("%lld\n", ans); return 0; }*/
#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...