Submission #1022136

#TimeUsernameProblemLanguageResultExecution timeMemory
1022136vjudge1Aliens (IOI16_aliens)C++17
16 / 100
1328 ms33540 KiB
#include <bits/stdc++.h>
#define ent '\n'

typedef long long ll;
using namespace std;
const int maxn = 1e6+12;

vector<int> g[maxn];
ll dp[maxn];
ll ndp[maxn];
int L[maxn];
int R[maxn];

struct line{
    ll k,b;
    line(ll x,ll y){
        k=x, b=y;
    }
    line(){

    }
    double find(line x){
        return double(x.b - b) / double(k - x.k);
    }
    ll get(ll x){
        return k * x + b;
    }
};

bool check(line nw, line last, line prl){
    if(nw.find(prl) <= last.find(prl))return 1;
    return 0;
}

struct convex{
    int ptr = 0;
    vector<line> l;
    convex(){
        l.clear();
        ptr=0;
    }
    void add(line x){
        while(l.size() && l.back().k == x.k && l.back().b > x.b){
            l.pop_back();
        }
        if(l.size() && l.back().k==x.k && l.back().b <= x.b){
            return;
        }
        while(l.size()>1 && check(x, l.back(), l[l.size()-2])){
            l.pop_back();
        }
        l.push_back(x);
    }
    ll get(ll x){
        if(!l.size()){
            return 1e18;
        }
        if(ptr >= l.size()){
            ptr = l.size()-1;
        }
        while(ptr + 1 < l.size() && l[ptr].get(x) > l[ptr+1].get(x)){
            ptr++;
        }
        while(ptr > 0 && l[ptr].get(x) > l[ptr-1].get(x)){
            ptr--;
        }
        return l[ptr].get(x);
    }
} cht;

long long take_photos(int n, int m, int k, vector<int> r, vector<int> c){
    for(int i=1;i<=m;i++){
        L[i] = 1e9;
    }
    m = 0;
    for(int i=0;i<n;i++){
        if(r[i] < c[i]){
            swap(r[i], c[i]);
        }
        r[i]++, c[i]++;
        L[r[i]] = min(L[r[i]], c[i]);
        R[c[i]] = max(R[c[i]], r[i]);
        m = max(m, r[i]);
    }
    for(int i=1;i<=m;i++){
        dp[i] = 1e18;
    }
    for(int t=1;t<=k;t++){
        cht.add({0, 0});
        for(ll i=1;i<=m;i++){
            R[i] = max(R[i], R[i-1]);
            ndp[i] = cht.get(i) + i * 1ll * i;
            g[max(i, (ll)R[i])].push_back(i);
            for(ll j:g[i]){
                ll b = j * 1ll * j + dp[R[j]];
                if(R[j] > j) b -= (R[j] - j) * 1ll * (R[j] - j);
                cht.add(line(-2 * j, b));
            }
        }
        for(int i=0;i<=m;i++){
            dp[i] = ndp[i];
        }
        cht.ptr = 0;
        cht.l.clear();
    }
    return dp[m];
}

Compilation message (stderr)

aliens.cpp: In member function 'll convex::get(ll)':
aliens.cpp:58:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         if(ptr >= l.size()){
      |            ~~~~^~~~~~~~~~~
aliens.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         while(ptr + 1 < l.size() && l[ptr].get(x) > l[ptr+1].get(x)){
      |               ~~~~~~~~^~~~~~~~~~
#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...