Submission #1022074

#TimeUsernameProblemLanguageResultExecution timeMemory
1022074vjudge1Aliens (IOI16_aliens)C++17
0 / 100
1 ms1116 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 4e3 + 100; int a[maxn]; int b[maxn]; int c[maxn]; int pref[maxn]; int suf[maxn]; ll dp[maxn][maxn]; vector<int> v; int get(int i, int j){ if(!i) return 0; ll x = max(0, (- i + a[i] + j + a[j]) / 2); return x * x; } void calc(int cnt, int l = 1, int r = v.size(), int tl = 1, int tr = v.size()){ int i = (l + r) >> 1, tm; for(int j = tl; j <= min(i, tr); j++){ ll x = dp[j-1][cnt-1] + get(v[j-1], v[i-1]); if(j > 1) x -= get(v[j-1], v[j-2]); if(dp[i][cnt] > x){ dp[i][cnt] = x; tm = j; } } if(l < r){ calc(cnt, l, i, tl, tm); calc(cnt, i+1, r, tm, tr); } } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){ for(int i = 0; i < n; i++){ r[i]++; c[i]++; int x = r[i] + c[i] - 1; a[x] = max(a[x], abs(r[i] - c[i]) + 1); } for(int i = 1; i < m * 2; i++){ pref[i] = max(pref[i-1] - 1, a[i]); } for(int i = m * 2 - 1; i > 0; i--){ suf[i] = max(suf[i+1] - 1, a[i]); } for(int i = 1; i < m * 2; i++){ if(max(pref[i-1], suf[i+1]) <= a[i] && a[i]){ v.push_back(i); } } for(int i = 0; i <= v.size(); i++){ fill(dp[i], dp[i] + k + 1, (ll)1e18); } dp[0][0] = 0; for(int cnt = 1; cnt <= k; cnt++){ calc(cnt); } return *min_element(dp[v.size()], dp[v.size()] + k + 1); }

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  for(int i = 0; i <= v.size(); i++){
      |                 ~~^~~~~~~~~~~
aliens.cpp: In function 'void calc(int, int, int, int, int)':
aliens.cpp:32:7: warning: 'tm' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |   calc(cnt, l, i, tl, tm);
      |   ~~~~^~~~~~~~~~~~~~~~~~~
#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...