Submission #275923

#TimeUsernameProblemLanguageResultExecution timeMemory
275923ggoorooAliens (IOI16_aliens)C++14
0 / 100
9 ms512 KiB
#include "aliens.h" #include<iostream> #include<cstdio> #include<algorithm> #define N 4005 #define F first #define S second typedef long long ll; using namespace std; ll i, j, M, d[N][N]; vector<ll> r, c; struct st { ll ri, ci, z; } a[N]; bool comp(st p, st q) { if (p.ri != q.ri) return p.ri < q.ri; else return p.ci > q.ci; } long long take_photos(int n, int m, int k, std::vector<int> rr, std::vector<int> cc) { ll i, j, w, pl, ans, t1, t2, en, mn, mx, sz; // if (n > 500) { // cout << 1/0; // return 0; // } for (i = n; i >= 1; i--) { rr[i] = rr[i - 1]; cc[i] = cc[i - 1]; } for (i = 1; i <= n; i++) { rr[i]++; cc[i]++; if (rr[i] > cc[i]) swap(rr[i], cc[i]); a[i].ri = rr[i]; a[i].ci = cc[i]; a[i].z = i; } a[0].ri = a[0].ci = a[0].z = 0; sort(a + 1, a + n + 1, comp); mx = 0; r.push_back(0); c.push_back(0); for (i = 1; i <= n; i++) { if (mx < a[i].ci) { mx = a[i].ci; r.push_back(a[i].ri); c.push_back(a[i].ci); } } sz = r.size() - 1; M = m * m; for (i = 0; i <= sz; i++) { en = i; if (k > i) en = k; for (j = 0; j <= en; j++) d[i][j] = M; } ans = M; d[0][0] = 0; for (i = 1; i <= sz; i++) { en = i; if (k < i) en = k; for (j = 1; j <= en; j++) { d[i][j] = M; for (w = i - 1; w >= 0; w--) { t1 = c[w]; t2 = r[w + 1]; pl = max(t1 - t2 + 1, 0ll); d[i][j] = min(d[i][j], d[w][j - 1] - pl * pl + (c[i] - r[w + 1] + 1) * (c[i] - r[w + 1] + 1)); } if (i == sz) ans = min(ans, d[i][j]); } } return ans; }

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:23:35: warning: unused variable 'mn' [-Wunused-variable]
   23 |  ll i, j, w, pl, ans, t1, t2, en, mn, mx, sz;
      |                                   ^~
#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...