Submission #426112

# Submission time Handle Problem Language Result Execution time Memory
426112 2021-06-13T14:16:19 Z 79brue Aliens (IOI16_aliens) C++14
0 / 100
1 ms 304 KB
#include <bits/stdc++.h>
#include "aliens.h"

using namespace std;

typedef long long ll;

int n, m, k;
ll x[500002], y[500002];

void makeArr(vector<int>&, vector<int>&);
pair<ll, int> calc(ll);

ll take_photos(int N, int M, int K, vector<int> r, vector<int> c){
    m = M, k = K;
    makeArr(r, c);
    k = min(n, k);

    ll L = 0, R = 1e12, ans = 1e12;
    while(L < R){
        ll M = (L+R)>>1;
        if(calc(M*2+1).second > k) ans = M, L = M + 1;
        else R = M;
    }
    return calc(ans*2).first - ans*2*(k-1);
}

void makeArr(vector<int> &r, vector<int> &c){
    vector<pair<int, int> > vec;
    int N = (int)r.size();
    for(int i=0; i<N; i++){
        if(r[i] > c[i]) swap(r[i], c[i]);
        vec.push_back(make_pair(r[i], c[i]));
    }
    sort(vec.begin(), vec.end(), [&](pair<int, int> &x, pair<int, int> &y){
        return x.second < y.second;
    });

    vector<pair<int, int> > stk;
    for(int i=0; i<N; i++){
        while(!stk.empty() && stk.back().first >= vec[i].first) stk.pop_back();
        stk.push_back(vec[i]);
    }

    n = (int)stk.size();
    for(int i=1; i<=n; i++) x[i] = stk[i-1].first, y[i] = stk[i-1].second;
}

ll quot(ll a, ll b){
    if(a>=0) return a/b;
    return a/b - !!(a%b);
}

struct Line{
    ll a, b, start; int cnt;
    Line(ll a, ll b, int cnt): a(a), b(b), cnt(cnt){}
    Line(ll a, ll b, ll start, int cnt): a(a), b(b), start(start), cnt(cnt){}

    ll val(ll x){
        return a*x+b;
    }

    ll cross(const Line &r)const{
        ll A = r.a - a;
        ll B = r.b - b;
        assert(A >= 0);

        B*=-1;
        return quot(B, A);
    }
};

ll DP[500002];
int cnt[500002];
vector<Line> vec;
int pnt = 0;

pair<ll, int> calc(ll lambda){
    for(int i=1; i<=n; i++){
        DP[i] = (y[i] - x[1] + 1) * (y[i] - x[1] + 1);
        cnt[i] = 1;
    }
    vec.clear();
    vec.push_back(Line(2, 3e12, -1e18, 0));

    for(int i=1; i<=n; i++){
        while(pnt >= (int)vec.size() || vec[pnt].start > y[i]) --pnt;
        while(pnt+1 < (int)vec.size() && y[i] >= vec[pnt+1].start) ++pnt;

        ll val = vec[pnt].val(y[i]) + y[i]*y[i] + lambda;
        if(DP[i] > val){
            DP[i] = val;
            cnt[i] = vec[i].cnt + 1;
        }

        if(i==n) break;
        Line tmp = Line(-(x[i+1]-1) * 2, (x[i+1]-1) * y[i] * 2 - y[i] * y[i] + DP[i], cnt[i]);
        if(x[i+1] > y[i]) tmp = Line(-(x[i+1]-1) * 2, (x[i+1]-1)*(x[i+1]-1) + DP[i], cnt[i]);

        while((int)vec.size() >= 2 && vec.back().start > tmp.cross(vec[(int)vec.size()-1])) vec.pop_back();
        tmp.start = tmp.cross(vec.back());
        vec.push_back(tmp);
    }

    return make_pair(DP[n], cnt[n]);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 296 KB Correct answer: answer = 4
3 Incorrect 1 ms 304 KB Wrong answer: output = -1999999999996, expected = 4
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 1
2 Correct 1 ms 204 KB Correct answer: answer = 4
3 Correct 1 ms 204 KB Correct answer: answer = 1
4 Incorrect 1 ms 204 KB Wrong answer: output = -1999999999991, expected = 5
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 296 KB Correct answer: answer = 4
3 Incorrect 1 ms 304 KB Wrong answer: output = -1999999999996, expected = 4
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 296 KB Correct answer: answer = 4
3 Incorrect 1 ms 304 KB Wrong answer: output = -1999999999996, expected = 4
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 296 KB Correct answer: answer = 4
3 Incorrect 1 ms 304 KB Wrong answer: output = -1999999999996, expected = 4
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct answer: answer = 4
2 Correct 1 ms 296 KB Correct answer: answer = 4
3 Incorrect 1 ms 304 KB Wrong answer: output = -1999999999996, expected = 4
4 Halted 0 ms 0 KB -