Submission #969184

#TimeUsernameProblemLanguageResultExecution timeMemory
969184VinhLuuAliens (IOI16_aliens)C++17
25 / 100
5 ms10332 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> //#define int long long #define ll long long #define fi first #define se second #define pb push_back #define all(lmao) lmao.begin(), lmao.end() using namespace std; typedef pair<int,int> pii; typedef tuple<int,int,int> tp; const int N = 1e6 + 5; //const int mod = 1e9 + 7; const int oo = 5e18; ll n, m, k, val[N], f[5][N], pre, nx, p[N]; void sol(int l,int r,int pl,int pr){ if(l > r) return; int mid = (l + r) / 2; f[nx][mid] = oo; int pos = pl; for(int i = pl; i <= min(mid - 1, pr); i ++){ ll w = 1ll * (p[mid] - p[i + 1] + val[p[i + 1]]) * (p[mid] - p[i + 1] + val[p[i + 1]]) + f[pre][i] - 1ll * max(0ll, val[p[i + 1]] - p[i + 1] + p[i]) * max(0ll, val[p[i + 1]] - p[i + 1] + p[i]); // cout << " " << mid << " " << i << " " << pre << " " << f[pre][i] << " " << w << " ee\n"; if(w < f[nx][mid]){ f[nx][mid] = w; pos = i; } } sol(l, mid - 1, pl, pos); sol(mid + 1, r, pos, pr); } ll take_photos(int _n,int _m,int _k,vector<int> R,vector<int> C){ n = _n, m = _m, k = _k; deque<int> sk; for(int i = 0; i < n; i ++){ ll r = ++R[i], c = ++C[i]; if(r <= c) val[c] = max(val[c], c - r + 1); else val[r] = max(val[r], r - c + 1); } for(int i = 1; i <= m; i ++){ if(!val[i]) continue; // cout << i << " " << val[i] << " u\n"; while(!sk.empty() && i - val[i] + 1 <= sk.front() - val[sk.front()] + 1) sk.pop_front(); sk.push_front(i); } vector<pii> vr; int t = 0; while(!sk.empty()){ p[++t] = sk.back(); sk.pop_back(); } n = t; if(n <= k){ ll ans = 1ll * val[p[1]] * val[p[1]]; for(int i = 2; i <= n; i ++){ ans += 1ll * val[p[i]] * val[p[i]] - 1ll * max(0ll, val[p[i]] - p[i] + p[i - 1]) * max(0ll, val[p[i]] - p[i] + p[i - 1]); } return ans; } nx = 1, pre = 0; // for(int i = 1; i <= n; i ++){ // cout << p[i] << " " << val[p[i]] << " t\n"; // } for(int i = 1; i <= n; i ++) f[0][i] = 1ll * (p[i] - p[1] + val[p[1]]) * (p[i] - p[1] + val[p[1]]); // for(int i = 1; i <= n; i ++) cout << f[0][i] << " "; // cout << "\n"; for(int j = 2; j <= k; j ++){ sol(j, n, j - 1, n); // cout << j << " l\n"; // for(int i = j; i <= n; i ++) cout << f[nx][i] << " "; // cout << "\n"; swap(pre, nx); } // cerr << f[pre][n] << "\n"; return f[pre][n]; } //#define lpv #ifdef lpv signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } int n, m, k; cin >> n >> m >> k; vector<int> r(n), c(n); for (int i = 0; i < n; ++i) cin >> r[i] >> c[i]; cout << take_photos(n, m, k, r, c) << "\n"; } #endif // lpv

Compilation message (stderr)

aliens.cpp:17:16: warning: overflow in conversion from 'double' to 'int' changes value from '5.0e+18' to '2147483647' [-Woverflow]
   17 | const int oo = 5e18;
      |                ^~~~
#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...