제출 #773593

#제출 시각아이디문제언어결과실행 시간메모리
773593JomnoiAliens (IOI16_aliens)C++17
12 / 100
45 ms2188 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; const int MAX_K = 1005; const int MAX_N = 1005; const long long INF = 1e18 + 7; int N, M, K; int id[MAX_N]; long long dp[MAX_K][MAX_N]; bool dead[MAX_N]; long long take_photos(int n, int m, int k, vector <int> r, vector <int> c) { N = n, M = m, K = k; if (K == N) { long long ans = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { long long l1 = 1ll * r[i] + c[i] - abs(r[i] - c[i]), r1 = 1ll * r[i] + c[i] + abs(r[i] - c[i]); long long l2 = 1ll * r[j] + c[j] - abs(r[j] - c[j]), r2 = 1ll * r[j] + c[j] + abs(r[j] - c[j]); if (l1 <= l2 and r2 <= r1) dead[j] = true; else if (l2 <= l1 and r1 <= r2) dead[i] = true; } } for (int i = 0; i < N; i++) { if (dead[i] == false) ans += 1ll * (abs(r[i] - c[i]) + 1) * (abs(r[i] - c[i]) + 1); } return ans; } for (int i = 0; i < N; i++) id[i] = i; sort(id, id + N, [&](const int &a, const int &b) { return r[a] < r[b]; }); for (int i = 1; i <= N; i++) dp[0][i] = INF; for (int k = 1; k <= K; k++) { for (int i = 1; i <= N; i++) { dp[k][i] = INF; for (int j = i; j >= 1; j--) { long long cost = (r[id[i - 1]] - r[id[j - 1]] + 1) * (r[id[i - 1]] - r[id[j - 1]] + 1); dp[k][i] = min(dp[k][i], cost + dp[k - 1][j - 1]); } } } long long ans = INF; for (int k = 1; k <= K; k++) ans = min(ans, dp[k][N]); return ans; }
#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...