Submission #170399

#TimeUsernameProblemLanguageResultExecution timeMemory
170399arnold518Aliens (IOI16_aliens)C++14
0 / 100
2 ms380 KiB
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 4000;
const int MAXK = 4000;

struct Point
{
    ll y, x;
};

struct CHT
{
    struct Line { ll a, b; };
    double cross(const Line &p, const Line &q) { return (double)(q.b-p.b)/(p.a-q.a); }
    vector<Line> S;

    void update(Line p)
    {
        while(S.size()>1 && cross(S[S.size()-1], p)<=cross(S[S.size()-1], S[S.size()-2])) S.pop_back();
        S.push_back(p);
    }

    int pos=0;
    ll query(ll x)
    {
        if(S.size()<=pos) pos=S.size()-1;
        else while(pos+1<S.size() && cross(S[pos], S[pos+1])<=x) pos++;
        return S[pos].a*x+S[pos].b;
    }

    void init()
    {
        S.clear();
        pos=0;
    }
} cht;

int N, M, K;
Point B[MAXN+10], A[MAXN+10];
ll dp[MAXK+10][MAXN+10];

ll take_photos(int _N, int _M, int _K, vector<int> R, vector<int> C)
{
    int i, j, k;
    N=_N; M=_M; K=_K;

    for(i=1; i<=N; i++) B[i]={min(R[i-1], C[i-1]), max(R[i-1], C[i-1])};
    sort(B+1, B+N+1, [&](const Point &p, const Point &q)
         {
             if(p.y==q.y) return p.x>q.x;
             return p.y<q.y;
         });

    int cnt=1;
    ll val=-1;
    for(i=1; i<=N; i++) if(val<B[i].x) A[cnt++]=B[i], val=B[i].x;
    N=cnt-1;
    for(i=1; i<=N; i++) if(A[i].x>A[i].y) swap(A[i].x, A[i].y);

    ll ans=0;
    for(i=1; i<=N; i++) ans+=(A[i].y-A[i].x+1)*(A[i].y-A[i].x+1);
    return ans;

    for(i=1; i<=N; i++) dp[1][i]=(A[i].y-A[1].x+1)*(A[i].y-A[1].x+1);
    for(i=2; i<=K; i++)
    {
        for(j=1; j<=N; j++)
        {
            dp[i][j]=numeric_limits<ll>::max();
            for(k=1; k<=j; k++) dp[i][j]=min(dp[i][j], dp[i-1][k-1]+(A[j].y-A[k].x+1)*(A[j].y-A[k].x+1));
        }
        continue;
        cht.init();
        for(j=1; j<=N; j++)
        {
            cht.update({-2*A[j].x, dp[i-1][j-1]+(A[j].x-1)*(A[j].x-1)});
            dp[i][j]=cht.query(A[j].y)+A[j].y*A[j].y+2*A[j].y;
        }
    }

    ans=numeric_limits<ll>::max();
    for(i=1; i<=K; i++) ans=min(ans, dp[i][N]);
    return ans;
}

Compilation message (stderr)

aliens.cpp: In member function 'll CHT::query(ll)':
aliens.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(S.size()<=pos) pos=S.size()-1;
            ~~~~~~~~^~~~~
aliens.cpp:33:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         else while(pos+1<S.size() && cross(S[pos], S[pos+1])<=x) pos++;
                    ~~~~~^~~~~~~~~
#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...