Submission #935009

#TimeUsernameProblemLanguageResultExecution timeMemory
935009dimashhhAliens (IOI16_aliens)C++17
41 / 100
2024 ms13876 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e6 + 3, MOD = 1e9 + 7;
 
typedef long long ll;
#include "aliens.h"
 
int n,m,k;
vector<pair<ll,ll>> a,x;
ll res;
ll dp[N],L[N],R[N];
int col[N];
ll f(ll pen){
    dp[0] = 0;
    col[0] = 0;
    for(int i = 1;i <= n;i++){
        for(int j = i;j >= 1;j--){
            if(j == i || dp[j - 1] + (R[i] - L[j] + 1) * (R[i] - L[j] + 1) -
               max(0ll, R[j - 1] - L[j] + 1) * max(0ll, R[j - 1] - L[j] + 1) + pen < dp[i]){
 
                dp[i] = (dp[j - 1] + (R[i] - L[j] + 1) * (R[i] - L[j] + 1) -
                                   max(0ll, R[j - 1] - L[j] + 1) * max(0ll, R[j - 1] - L[j] + 1) + pen);
                col[i] = col[j - 1] + 1;
            }
        }
    }
    res = dp[n];
    return col[n];
}
long long take_photos(int nn,int mm,int kk,vector<int> rr,vector<int> cc){
    n = nn;
    m = mm;
    k = kk;
    for(int i = 1;i <= n;i++){
        int l = rr[i - 1],r = cc[i - 1];
        ++l;++r;
        if(l > r){
            swap(l,r);
        }
        a.push_back({l,-r});
    }
    sort(a.begin(),a.end());
    int mx = 0;
    x.push_back({0,0});
    for(auto [l,r]:a){
        r = -r;
        if(r > mx){
            mx = r;
            x.push_back({l,r});
        }
    }
    sort(x.begin(),x.end());
    n = (int)x.size() - 1;
    for (int i = 1; i <= n; i++) {
        L[i] = x[i].first;
        R[i] = x[i].second;
    }
    ll l = -1,r = 1e15;
    k = min(k,n);
    while(r - l > 1) {
        ll mid = (l + r) >> 1;
        if (f(mid) >= k) {
            l = mid;
        } else {
            r = mid;
        }
    }
    ll x = f(l);
    return res - k * 1ll * l;
}

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:70:8: warning: unused variable 'x' [-Wunused-variable]
   70 |     ll x = f(l);
      |        ^
#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...