Submission #1021962

#TimeUsernameProblemLanguageResultExecution timeMemory
1021962vjudge1Aliens (IOI16_aliens)C++17
12 / 100
200 ms4440 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];

int get(int i, int j){
	if(!i) return 0;
    ll x = max(0, (- i + a[i] + j + a[j]) / 2);
    return x * x;
}

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);
	}
	vector<int> v;
	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 i = 1; i <= v.size(); i++){
		for(int cnt = 1; cnt <= k; cnt++){
			for(int j = 1; j <= i; 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]);
				dp[i][cnt] = min(dp[i][cnt], x);
			}
		}
	}
	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:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i = 0; i <= v.size(); i++){
      |                 ~~^~~~~~~~~~~
aliens.cpp:42:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(int i = 1; i <= v.size(); i++){
      |                 ~~^~~~~~~~~~~
#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...