제출 #170393

#제출 시각아이디문제언어결과실행 시간메모리
170393arnold518Aliens (IOI16_aliens)C++14
12 / 100
10 ms4344 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;
    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, 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++) swap(A[i].x, A[i].y);

    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++)
    {
        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;
        }
    }

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

컴파일 시 표준 에러 (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...