Submission #206671

#TimeUsernameProblemLanguageResultExecution timeMemory
206671mieszko11bAliens (IOI16_aliens)C++14
25 / 100
18 ms11640 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; ll INF = 1e18; ld EPS = 1e-10; inline ll sq(ll x) { return x * x; } struct Parabolas { int ind = 0; vector<ll> A, B; ld intersection(ll a, ll b, ll c, ll d) { return (ld(sq(c) + d - sq(a) - b) / ld(2LL * c - 2LL * a)); } bool ok(ll a, ll b, ll c, ll d) { if(a == c) return false; //~ cout << "ok" << (ld(sq(c) + d - sq(a) - b) / ld(2LL * c - 2LL * a)) + EPS << endl; return intersection(a, b, c, d) + EPS > max(a, c); } void clear() { ind = 0; A.clear(); B.clear(); } void insert(ll a, ll b) { //~ cout << "ins"<<a << " "<< b << endl; while((!A.empty() && !ok(A.back(), B.back(), a, b)) || (A.size() >= 2 && intersection(A[A.size()-2], B[B.size()-2], A.back(), B.back()) > intersection(a, b, A.back(), B.back())) ){ A.pop_back(); B.pop_back(); if(ind == A.size()) ind--; } ind = max(ind, 0); 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; //~ } ll query(ll x) { if(A.size() == 0) return INF; while(ind + 1 < A.size() && sq(x - A[ind + 1]) + B[ind + 1] <= sq(x - A[ind]) + B[ind]) ind++; //~ for(int i = 0 ; i < A.size() ; i++) //~ cout << "(" << A[i] << ", " << B[i] << ": " << sq(x - A[i]) + B[i] << ") "; //~ cout << endl << "x=" << x << " ind=" << ind << endl; return sq(x - A[ind]) + B[ind]; } }; 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, x[i] - d[i + 1] + 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 'void Parabolas::insert(ll, ll)':
aliens.cpp:44:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(ind == A.size()) ind--;
       ~~~~^~~~~~~~~~~
aliens.cpp: In member function 'll Parabolas::query(ll)':
aliens.cpp:63:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(ind + 1 < A.size() && sq(x - A[ind + 1]) + B[ind + 1] <= sq(x - A[ind]) + B[ind])
         ~~~~~~~~^~~~~~~~~~
#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...