Submission #206651

#TimeUsernameProblemLanguageResultExecution timeMemory
206651mieszko11bAliens (IOI16_aliens)C++14
0 / 100
6 ms2424 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; using ll = long long; ll INF = 1e18; inline ll sq(ll x) { return x * x; } struct Parabolas { vector<ll> A, B; void clear() { A.clear(); B.clear(); } void insert(ll a, ll b) { //~ cout << "ins"<<a << " "<< b << endl; A.push_back(a); B.push_back(b); } ll query(ll x) { ll res = INF; for(int i = 0 ; i < A.size() ; i++) res= min(res, sq(x-A[i]) + B[i]); return res; } }; int l, k; int d[100007], x[100007]; int maxx[1000007]; Parabolas P; ll dp[507][507]; // k, n ll calc_dp() { for(int i = 0 ; i < 507 ; i++) for(int j = 0 ; j < 507 ; j++) dp[i][j] = INF; dp[0][0] = 0; for(int j = 1 ; j <= k ; j++) { P.clear(); for(int i = 0 ; i <= l ; i++) { if(i > 0) dp[j][i] = P.query(x[i]); //~ cout << i << " " << j << " " << dp[j][i] << endl; if(i < l && dp[j - 1][i] != INF) P.insert(d[i + 1] - 1, dp[j - 1][i] - sq(max(0, d[i] + x[i] - d[i + 1]))); } } ll res = INF; for(int i = 0 ; i <= k ; i++) res = min(res, dp[i][l]); return res; } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { ::k = k; for(int i = 0 ; i < n ; i++) { if(c[i] >= r[i]) maxx[r[i] + 1] = max(maxx[r[i] + 1], c[i] + 1); else maxx[c[i] + 1] = max(maxx[c[i] + 1], r[i] + 1); } for(int i = 1 ; i <= m ; i++) { if(maxx[i] && (l == 0 || x[l] < maxx[i])) { l++; d[l] = i; x[l] = maxx[i]; //~ cout << d[l] << " " << x[l] << endl; } } return calc_dp(); }

Compilation message (stderr)

aliens.cpp: In member function 'll Parabolas::query(ll)':
aliens.cpp:30:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < A.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...