제출 #1331054

#제출 시각아이디문제언어결과실행 시간메모리
1331054Zbyszek99Ski 2 (JOI24_ski2)C++20
100 / 100
728 ms3444 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#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(long long i = 0; i < (b); ++i)
#define rep2(i,a,b) for(long long 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;

struct elm
{
    __int128_t h,cnt,cost;
};

int n;
//__int128_t lol :)
__int128_t K;

__int128_t dp[2][301][301];
__int128_t INF2;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //random_start();
    ll K2;
    cin >> n >> K2;
    K = K2;
    map<int,__int128_t> cnt_map;
    map<int,__int128_t> cost_map;
    __int128_t const_cost = 0;
    INF2 = (__int128_t)1e18*(__int128_t)1e9;
    ll min_ = 1e9+1;
    rep(i,n)
    {
        ll h,c;
        cin >> h >> c;
        min_ = min(min_,h);
        const_cost += -K*h;
        cnt_map[h]++;
        cnt_map[h+1] += 0;
        if(cost_map.find(h+1) == cost_map.end()) cost_map[h+1] = INF2;
        if(cost_map.find(h) == cost_map.end()) cost_map[h] = c;
        cost_map[h] = min(cost_map[h],(__int128_t)c);
    }
    const_cost += min_*K;
    cnt_map[min_]--;
    vector<elm> elms;   
    forall(it,cnt_map) elms.pb({it.ff,it.ss,cost_map[it.ff]});
    rep(d,2) rep(i,n+1) rep(j,n+1) dp[d][i][j] = INF2;
    dp[0][0][0] = 0;
    elms.pb({(int)1e9+n+2,0,0});
    __int128_t cur_min = INF2;
    rep(e,siz(elms)-1)
    {
        elm el = elms[e];
        rep2(i,0,n) rep2(j,0,n) dp[1][i][j] = INF2;
        rep2(i,0,n) for(int j = n; j >= 0; j--) if(j+el.cnt <= n) dp[0][i][j+el.cnt] = dp[0][i][j];
        rep2(i,0,n) rep2(j,0,el.cnt-1) dp[0][i][j] = INF2;
        for(int i = n; i >= 0; i--) for(int j = n; j >= 0; j--)
        {
            int del = min(i,j);
            dp[1][i][j-del] = min(dp[1][i][j-del],dp[0][i][j]+del*el.h*K);
        }
        rep2(i,0,n) rep2(j,0,n)
        {
            dp[0][i][j] = dp[1][i][j];
            dp[1][i][j] = INF2;
        }
        rep2(i,0,n-1) rep2(j,0,n) dp[0][i+1][j-1] = min(dp[0][i+1][j-1],dp[0][i][j]+cur_min+el.h*K);
        if(el.h == min_)
        {
            for(int i = n-1; i >= 0; i--) rep2(j,0,n) dp[0][i+1][j] = dp[0][i][j];
            rep2(j,0,n) dp[0][0][j] = INF2;
        }
        if(elms[e+1].h == el.h+1)
        {
            cur_min = min(cur_min,el.cost);
            continue;
        }
        else
        {
            rep2(i,1,n) rep2(j,0,n)
            {
                __int128_t del = min((ll)j,(ll)(elms[e+1].h-1-el.h)*i);
                __int128_t blocks = (del/i);
                __int128_t add = del*el.h+i*blocks*(blocks+1)/2+(del-blocks*i)*(blocks+1);
                dp[1][i][j-del] = min(dp[1][i][j-del],dp[0][i][j]+add*K);
            }
            rep2(i,0,n) rep2(j,0,n) dp[0][i][j] = dp[1][i][j];
        }
    }
    __int128_t ans = INF2;
    rep2(i,0,n) ans = min(ans,dp[0][i][0]);
    cout << (ll)(ans+const_cost) << "\n";
}
#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...