제출 #157641

#제출 시각아이디문제언어결과실행 시간메모리
157641dolphingarlicAliens (IOI16_aliens)C++14
컴파일 에러
0 ms0 KiB
// #include "aliens.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define x first
#define y second

ll sq(ll a) { return a * a; }
bool cmp(pair<int, int> a, pair<int, int> b) {
    if (a.x == b.x) return (a.y > b.y);
    return a.x < b.x;
}

ll dp[100001], cnt[100001]{1};
vector<pair<int, int>> useful;
int N;

float slope(int i, int j) {
    return (sq(useful[j + 1].y) - sq(useful[i + 1].y) + dp[j] - dp[i] +
                   sq(max(useful[i].x - useful[i + 1].y + 1, 0)) -
                   sq(max(useful[j].x - useful[j + 1].y + 1, 0))) /
           (float)(useful[j + 1].y - useful[i + 1].y);
}

void compute(int lambda, int k) {
    deque<int> dq;
    dq.push_back(0);
    dp[0] = lambda + sq(useful[0].y - useful[0].x + 1);

    for (int i = 1; i < N; i++) {
        while (dq.size() > 1 && slope(dq[0], dq[1]) >= 2 * (useful[i].x + 1)) dq.pop_front();

        int opt = dq.front();
        dp[i] = sq(useful[i].y - useful[opt + 1].x + 1) + dp[opt] -
                sq(max(0, useful[opt].y - useful[opt + 1].x + 1)) + lambda;
        cnt[i] = cnt[opt] + 1;

        if (dp[i] >= sq(useful[i].y - useful[0].x + 1) + lambda) {
            dp[i] = sq(useful[i].y - useful[0].x + 1) + lambda;
            cnt[i] = 1;
        }

        while (dq.size() > 1 && slope(dq[dq.size() - 2], dq.back()) <= slope(dq.back(), i)) dq.pop_back();
        dq.push_back(i);
    }
}

ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
    vector<pair<int, int>> points;
    for (int i = 0; i < n; i++) {
        int x = r[i], y = c[i];
        if (x > y) swap(x, y);
        points.push_back({x, y});
    }
    sort(points.begin(), points.end(), cmp);
    for (int i = 0; i < n; i++)
        if (useful.empty() || useful.back().y < points[i].y)
            useful.push_back(points[i]);
    N = useful.size();

    ll l = 0, u = (ll)m * m;
    while (l != u) {
        ll mid = (l + u) / 2;
        compute(mid, k);

        if (cnt[N - 1] <= k) u = mid;
        else l = mid + 1;
    }
    compute(l, k);

    return dp[N - 1] - l * cnt[N - 1];
}

#include <cstdio>
#include <cassert>

int main() {
    int n, m, k;
    assert(3 == scanf("%d %d %d", &n, &m, &k));
    std::vector<int> r(n), c(n);
    for (int i = 0; i < n; i++) {
        assert(2 == scanf("%d %d", &r[i], &c[i]));
    }
    long long ans = take_photos(n, m, k, r, c);
    
    
    printf("%lld\n", ans);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

/tmp/ccqCV1QX.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccrJM41c.o:aliens.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status