제출 #388858

#제출 시각아이디문제언어결과실행 시간메모리
388858KeshiAliens (IOI16_aliens)C++17
0 / 100
1 ms208 KiB
//In the name of God #include <bits/stdc++.h> #include "aliens.h" using namespace std; typedef long long ll; typedef pair<ll, ll> pll; const ll maxn = 5e4 + 100; const ll maxk = 105; const ll mod = 1e9 + 7; const ll inf = 1e18; #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout); #define pb push_back #define Mp make_pair #define F first #define S second #define Sz(x) ll((x).size()) #define all(x) (x).begin(), (x).end() vector<pll> vec; ll dp[maxk][maxn]; void solve(ll k, ll l, ll r, ll s, ll e){ if(l >= r) return; ll mid = (l + r) >> 1; ll opt = s; dp[k][mid] = inf; for(ll i = s; i < e && i <= mid; i++){ ll x = dp[k - 1][i - 1] + (vec[mid].F - vec[i].S + 1) * (vec[mid].F - vec[i].S + 1); if(x < dp[k][mid]){ dp[k][mid] = x; opt = i; } } solve(k, l, mid, opt, e); solve(k, mid + 1, r, s, opt + 1); return; } long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) { vector<pll> p(n); vec.pb(Mp(-1, -1)); for(ll i = 0; i < n; i++){ if(r[i] < c[i]) swap(r[i], c[i]); p[i] = Mp(c[i], -r[i]); } sort(all(p)); ll mx = -1; for(ll i = 0; i < n; i++){ p[i].S *= -1; if(p[i].S > mx){ vec.pb(Mp(p[i].S, p[i].F)); mx = p[i].S; } } n = Sz(vec) - 1; k = min(k, n); fill(dp[0] + 1, dp[0] + n + 1, inf); for(ll i = 1; i <= k; i++){ solve(i, 1, n + 1, 1, n + 1); } return dp[k][n]; } /*int main(){ fast_io; 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...