제출 #1212832

#제출 시각아이디문제언어결과실행 시간메모리
1212832Zbyszek99Aliens (IOI16_aliens)C++20
4 / 100
1 ms584 KiB
#include "aliens.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

vector<pll> get_real_points(vector<pll> p)
{
    rep(i,siz(p)) p[i].ss *= -1;
    sort(all(p));
    rep(i,siz(p)) p[i].ss *= -1;
    int cur_max = -1e9;
    vector<pll> ans = {{-1,-1}};
    forall(it,p)
    {
        if(it.ss > cur_max)
        {
            ans.pb(it);
            cur_max = it.ss;
        }
    }
    return ans;
}

ll dp[4001][4001];

struct line
{
    ll a = 1e15,b = 1e15;
    int k =-1,last_vis = -1;
    ll operator()(ll x)
    {
        return a + b*x;
    }
};

const int tree_siz = 1024*2048-1;
line nodes[tree_siz+1];
int cur_iter = 0;

void add_line(int akt, int l, int r, line l2)
{
    if(l > r) return;
    if(nodes[akt].last_vis < cur_iter)
    {
        nodes[akt] = l2;
        return;
    }
    ll x = (l+r)/2;
    if(l2(x) < nodes[akt](x)) swap(l2,nodes[akt]);
    ll d1 = (l2.a - nodes[akt].a);
    ll d2 = (nodes[akt].b - l2.b);
    if(d2 < 0)
    {
        d1 *= -1;
        d2 *= -1;
    }
    if(d2 == 0) return;
    if(d1 > x * d2 || (l2(x) == nodes[akt](x) && l2.b < nodes[akt].b))
    {   
        add_line(akt*2,(l+r)/2+1,r,l2);
    }
    else
    {
        add_line(akt*2+1,l,(l+r)/2,l2);
    }
}

line get_best(int akt, int l, int r, int x)
{
    line best = nodes[akt];
    if(l == r) return best;
    line best2;
    if(x <= (l+r)/2)
    {
        best2 = get_best(akt*2,l,(l+r)/2,x);
    }
    else
    {
        best2 = get_best(akt*2+1,(l+r)/2+1,r,x);
    }
    if(best.last_vis != cur_iter) return best2;
    if(best2.last_vis != cur_iter) return best;
    if(best(x) < best2(x)) return best;
    return best2;
}

ll take_photos(int n, int m, int k, vi r, vi c) 
{
    vector<pll> points;
    rep(i,n)
    {
        if(c[i] - r[i] < 0)
        {
            points.pb({c[i],r[i]});
        }
        else
        {
            points.pb({r[i],c[i]});
        }
    }
    points = get_real_points(points);
    n = siz(points)-1;
    rep2(i,1,n) dp[i][0] = 1e17;
    dp[0][0] = 0;
    rep2(kk,1,k)
    {
        cur_iter++;
        rep2(i,1,n)
        {
            dp[i][kk] = (points[i].ss - points[1].ff+1) * (points[i].ss - points[1].ff+1);
            if(i != 1)
            {
                line l = get_best(1,0,tree_siz/2,points[i].ss);
                dp[i][kk] = min(dp[i][kk],l(points[i].ss) + points[i].ss * points[i].ss + 2*points[i].ss+1);
            }
            if(i != n)
            {
                line new_line;
                new_line.a = dp[i][kk-1]-2*points[i+1].ff + points[i+1].ff * points[i+1].ff - max(0LL,(points[i].ss - points[i+1].ff+1)) * max(0LL,points[i].ss - points[i+1].ff+1);
                new_line.b = -2*points[i+1].ff;
                new_line.k = kk-1;
                new_line.last_vis = cur_iter;
                add_line(1,0,tree_siz/2,new_line);
            }
        }
    }
    return dp[n][k];
}

컴파일 시 표준 에러 (stderr) 메시지

aliens.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...