제출 #1036780

#제출 시각아이디문제언어결과실행 시간메모리
1036780c2zi6Aliens (IOI16_aliens)C++14
41 / 100
2070 ms94312 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "aliens.h" ll square(ll a) { return a*a; } ll take_photos(int n, int m, int k, VI R, VI C) { VPI pts; rep(i, n) { int r = R[i]; int c = C[i]; if (r > c) swap(r, c); pts.pb({r, c}); } { VPI tmp; tmp.pb({-1, -1}); sort(all(pts)); rep(i, n) { if (i == n-1 || pts[i+1].ff != pts[i].ff) { if (!tmp.size() || tmp.back().ss < pts[i].ss) { tmp.pb(pts[i]); } } } pts = tmp; n = pts.size()-1; } auto cost = [&](int j, int i) { return square(pts[i].ss - pts[j+1].ff + 1) - square(max(0, pts[j].ss - pts[j+1].ff + 1)); }; VVL dp(n+1, VL(k+1, 1e18)); VVI opt(n+1, VI(k+1)); replr(j, 0, k) dp[0][j] = 0; /*replr(i, 1, n) {*/ /* replr(j, 1, k) {*/ /* replr(l, 0, i-1) {*/ /* ll cur = dp[l][j-1] + cost(l, i);*/ /* if (cur < dp[i][j]) {*/ /* dp[i][j] = cur;*/ /* opt[i][j] = l;*/ /* }*/ /* }*/ /* }*/ /*}*/ replr(D, 1-k, n-1) replr(i, 1, n) { int j = i-D; if (j < 1 || j > k) continue; int mn = 0; int mx = i-1; if (i-1 >= 1) mn = opt[i-1][j]; if (j+1 <= k) mx = opt[i][j+1]; replr(l, mn, mx) { ll cur = dp[l][j-1] + cost(l, i); if (cur < dp[i][j]) { dp[i][j] = cur; opt[i][j] = l; } } } return dp[n][k]; }
#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...