Submission #25233

#TimeUsernameProblemLanguageResultExecution timeMemory
25233RezwanArefin01Aliens (IOI16_aliens)C++14
4 / 100
0 ms2024 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll solveSubtask1(int n, int m, int k, std::vector<int> r, std::vector<int> c) { bool grid[m][m]; memset(grid,0, sizeof grid); for(int i=0; i<n; i++) { int x = r[i], y = c[i]; if(y < x) swap(x, y); for(int j=x; j <= y; j++) for(int k = x; k <= y; k++) grid[j][k] = 1; } int ans = 0; for(int i=0; i<m; i++) for(int j=0; j<m; j++) ans += grid[i][j]; return ans; } #define sq(a) ((a) * (a)) ll solveSubtask2(int n, int m, int kk, std::vector<int> r, std::vector<int> c) { sort(r.begin(), r.end()); r.erase(unique(r.begin(), r.end()), r.end()); ll dp[kk+1][n+1]; memset(dp, 0x3f, sizeof dp); for(int i=1; i <= n; i++) { dp[1][i] = sq(r[i-1] - r[0] + 1); } for(int k=2; k <= kk; k++) { for(int i=1; i<=n; i++) { for(int j=0; j < i; j++) { dp[k][i] = min(dp[k][i], dp[k-1][j] + sq(r[i-1] - r[j] + 1)); } } } ll Min = 1e18; for(int k = 1; k <= kk; k++) Min = min(Min, dp[k][n]); return dp[kk][n]; } ll take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { if(n <= 50 && m <= 100 && n == k) return solveSubtask1(n, m, k, r, c); bool f = 0; for(int i=0; i<n; i++) if(r[i] != c[i]) { f = 1; break; } if(!f) return solveSubtask2(n, m, k, r, c); return 0; }
#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...