Submission #934996

#TimeUsernameProblemLanguageResultExecution timeMemory
934996dimashhhAliens (IOI16_aliens)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 3, MOD = 1e9 + 7;

typedef long long ll;

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++){
        dp[i] = 1e15;
        for(int j = i;j >= 1;j--){
            if(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] = min(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];
}
void test(){
    cin >> n >> m >> k;
    for(int i = 1;i <= n;i++){
        int l,r;
        cin >> l >> r;
        ++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});
        }
    }
    n = (int)x.size() - 1;
    for (int i = 1; i <= n; i++) {
        L[i] = x[i].first;
        R[i] = x[i].second;
//        cout << L[i] << ' ' << R[i] << '\n';
    }
    ll l = -1e11,r = 1e11;
    while(r - l > 1) {
        ll mid = (l + r) >> 1;
//        cout << l << ' ' << r << ' ' << mid << ' ' << f(mid) << '\n';
        if (f(mid) >= k) {
            l = mid;
        } else {
            r = mid;
        }
    }
    f(l);
    cout << res - k * l << '\n';
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int T = 1;
//    cin >> T;
    while (T--)
        test();
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccNPRKS3.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccN1pFo7.o:aliens.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccNPRKS3.o: in function `main':
grader.cpp:(.text.startup+0xf0): undefined reference to `take_photos(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status