답안 #474357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474357 2021-09-18T05:39:00 Z evenharder Aliens (IOI16_aliens) C++14
0 / 100
1 ms 332 KB
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
struct line {
    ll a, b, i;
    line(ll a=0, ll b=0, ll i=0) : a(a), b(b), i(i) {}
    ll calc(ll x) { return a*x+b;}
};
bool check_back(line& p0, line& p1, line& p2) {
    return (p1.b - p0.b) * (p1.a - p2.a) >= (p0.a - p1.a) * (p2.b - p1.b);
}
bool check_front(ll x, line& p0, line& p1) {
    return x * (p0.a - p1.a) >= (p1.b - p0.b);
}
struct ConvexHull {
    size_t apos = 0;
    vector<line> v;
    void insert(line p) {
        while(1) {
            size_t sz = v.size();
            if(sz - apos >= 2 && check_back(v[sz-2], v[sz-1], p)) {
                v.pop_back();
                sz--;
            }
            else break;
        }
        v.push_back(p);
    }
    pll query(ll x) {
        while(1) {
            size_t sz = v.size();
            if(sz - apos >= 2 && check_front(x, v[apos], v[apos+1]))
                apos++;
            else break;
        }
        return pll{v[apos].calc(x), v[apos].i};
    }
};

pll take_photos_lambda(vector<pii>& v1, ll eff) {
    ConvexHull ch;
    ll val = 0;
    ll cnt = 0;
    for(int i=0;i<v1.size();i++) {
        ch.insert(line{-2LL * (v1[i].second-1),
            val + 1LL * (v1[i].second-1) * (v1[i].second-1)
            - (i && v1[i-1].first >= v1[i].second ? 1LL * (v1[i-1].first - v1[i].second + 1) * (v1[i-1].first - v1[i].second + 1) : 0),
            cnt
        });
        pll res = ch.query(v1[i].first);
        val = res.first + v1[i].first * v1[i].first + eff;
        cnt = res.second + 1;
    }
    return pll{val, cnt};
}

ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
    vector<pii> v(n), v1;
    for(int i=0;i<n;i++) {
        v[i] = pii{max(c[i], r[i]), min(c[i], r[i])};
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for(int i=0;i<n;i++) {
        if(!v1.empty() && v1.back().first == v[i].first) {
            continue;
        }
        if(!v1.empty() && v1.back().second >= v[i].second) {
            v1.pop_back();
        }
        v1.push_back(v[i]);
    }
    ll leff = 0, reff = 1LL*m*m;
    int lind = v1.size(), rind = 1; // decreases when leff increase
    while(reff - leff >= 2) {
        ll meff = (leff + reff) / 2;
        pll res = take_photos_lambda(v1, meff);
        if(res.second < rind) res.second = rind;
        if(res.second > lind) res.second = lind;
        if(res.second == k) {
            return res.first - k * meff;
        }
        else if(res.second > k) {
            lind = res.second;
            leff = meff;
        }
        else {
            rind = res.second;
            reff = meff;
        }
    }
    // answer is max(take_photos_lambda().first - k * eff) for all eff when minimizing answer
    return max(take_photos_lambda(v1, leff).first - k * leff, take_photos_lambda(v1, reff).first - k * reff);
}

Compilation message

aliens.cpp: In function 'pll take_photos_lambda(std::vector<std::pair<int, int> >&, ll)':
aliens.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i=0;i<v1.size();i++) {
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 292 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 1 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Incorrect 0 ms 204 KB Wrong answer: output = 5476, expected = 7696
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 1
2 Correct 0 ms 288 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 1
4 Correct 1 ms 204 KB Correct answer: answer = 5
5 Correct 1 ms 204 KB Correct answer: answer = 41
6 Correct 1 ms 204 KB Correct answer: answer = 71923
7 Correct 1 ms 204 KB Correct answer: answer = 77137
8 Incorrect 1 ms 332 KB Wrong answer: output = -53330, expected = 764
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 292 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 1 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Incorrect 0 ms 204 KB Wrong answer: output = 5476, expected = 7696
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 292 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 1 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Incorrect 0 ms 204 KB Wrong answer: output = 5476, expected = 7696
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 292 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 1 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Incorrect 0 ms 204 KB Wrong answer: output = 5476, expected = 7696
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 292 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 4
4 Correct 1 ms 204 KB Correct answer: answer = 12
5 Correct 1 ms 204 KB Correct answer: answer = 52
6 Correct 1 ms 204 KB Correct answer: answer = 210
7 Correct 0 ms 204 KB Correct answer: answer = 88
8 Incorrect 0 ms 204 KB Wrong answer: output = 5476, expected = 7696
9 Halted 0 ms 0 KB -