Submission #274712

#TimeUsernameProblemLanguageResultExecution timeMemory
274712stoyan_malininAliens (IOI16_aliens)C++14
12 / 100
229 ms3456 KiB
#include "aliens.h" //#include "grader.cpp" #include <cmath> #include <vector> #include <iostream> #include <algorithm> using namespace std; const int MAXN = 505; struct Point { int r, c; Point(){} Point(int r, int c) { this->r = r; this->c = c; } }; bool cmpCol(Point A, Point B) { if(A.c!=B.c) return A.c<B.c; return A.r<B.r; } int n, m, k; long long dp[MAXN][MAXN]; vector <Point> v; int squareSz[MAXN][MAXN], leftestCover[MAXN][MAXN]; void init() { for(int i = 0;i<n;i++) { for(int j = 0;j<=k;j++) { dp[i][j] = 6969696966969LL; } } vector <bool> toRemove; toRemove.assign(v.size(), false); vector <Point> newV; for(int i = 0;i<v.size();i++) { if(toRemove[i]==false) newV.push_back(v[i]); } v = newV; n = v.size(); for(int r = 0;r<v.size();r++) { int maxDist = -1; for(int l = r;l>=0;l--) { maxDist = max(maxDist, abs(v[l].c-v[l].r)+(v[r].c-v[l].c)); squareSz[l][r] = maxDist + 1; } } for(int i = 0;i<n;i++) { int d = squareSz[i][i]; for(int j = 0;j<i;j++) { if(v[i].c-v[j].c<d && abs(v[i].c-v[j].r)<d) { toRemove[j] = true; } } } //cout << "->" << leftestCover[1][4] << '\n'; } long long squareNum(long long x) { if(x<0) return 0; return x*x; } long long take_photos(int _n, int _m, int _k, vector<int> r, vector<int> c) { n = _n; m = _m; k = _k; for(int i = 0;i<n;i++) { if(c[i]<r[i]) swap(c[i], r[i]); } for(int i = 0;i<n;i++) v.push_back(Point(r[i], c[i])); sort(v.begin(), v.end(), cmpCol); init(); for(int i = 0;i<n;i++) { //cout << v[i].r << " --- " << v[i].c << '\n'; //if(i!=n-1 && v[i].c==v[i+1].c) continue; dp[i][0] = squareNum(squareSz[0][i]); for(int j = 1;j<k;j++) { int cover = i; for(int p = i;p>=1;p--) { int side = squareSz[p][i]; //if(v[p].c==v[p-1].c) continue; dp[i][j] = min(dp[i][j], dp[p-1][j-1] + squareNum(squareSz[p][i]) - squareNum(v[p-1].c-(v[i].c-squareSz[p][i]))); //cout << p << " -> " << squareNum(v[p-1].c-(v[i].c-squareSz[p][i])) << " " << side << '\n'; } } //cout << dp[i][0] << " $$$ " << dp[i][1] << '\n'; } long long answer = 6996969969696996LL; for(int i = 0;i<k;i++) answer = min(answer, dp[n-1][i]); return answer; } /* 5 7 2 0 3 4 4 4 6 4 5 4 6 5 10 2 0 3 3 4 4 3 3 3 4 2 */

Compilation message (stderr)

aliens.cpp: In function 'void init()':
aliens.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 0;i<v.size();i++)
      |                   ~^~~~~~~~~
aliens.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int r = 0;r<v.size();r++)
      |                   ~^~~~~~~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:115:21: warning: unused variable 'side' [-Wunused-variable]
  115 |                 int side = squareSz[p][i];
      |                     ^~~~
aliens.cpp:112:17: warning: unused variable 'cover' [-Wunused-variable]
  112 |             int cover = 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...