結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー nanophoto12nanophoto12
提出日時 2017-08-20 14:08:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,422 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 91,996 KB
実行使用メモリ 9,036 KB
最終ジャッジ日時 2024-04-22 18:13:34
合計ジャッジ時間 7,026 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 25 ms
5,376 KB
testcase_14 AC 28 ms
5,376 KB
testcase_15 AC 69 ms
5,504 KB
testcase_16 WA -
testcase_17 AC 121 ms
7,168 KB
testcase_18 AC 21 ms
5,376 KB
testcase_19 AC 156 ms
7,808 KB
testcase_20 AC 56 ms
5,376 KB
testcase_21 AC 156 ms
8,448 KB
testcase_22 AC 58 ms
5,376 KB
testcase_23 AC 156 ms
8,064 KB
testcase_24 AC 38 ms
5,376 KB
testcase_25 AC 155 ms
8,064 KB
testcase_26 AC 19 ms
5,376 KB
testcase_27 AC 114 ms
6,784 KB
testcase_28 AC 109 ms
6,400 KB
testcase_29 AC 62 ms
5,376 KB
testcase_30 AC 161 ms
7,936 KB
testcase_31 AC 25 ms
5,376 KB
testcase_32 AC 28 ms
5,376 KB
testcase_33 AC 171 ms
8,448 KB
testcase_34 AC 171 ms
8,832 KB
testcase_35 WA -
testcase_36 AC 169 ms
8,832 KB
testcase_37 AC 173 ms
8,576 KB
testcase_38 AC 170 ms
8,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> t3;

using namespace std;

int N,K;
ll T[202020],D[202020];
int NG[202020];
ll dp[202020];


int ok(int can) {
    int pre=-1<<30;
    for(int i = 0;i < N;i++)
    {
        if(D[i]>can)
        {
            if(T[i]-pre<K)
            {
               return 0;
            }
            pre = (int)T[i];
        }
    }
    return 1;
}


void solve() {
    
    cin>>N>>K;
    for(int i = 0;i < N;i++) cin>>T[i]>>D[i];
    
    //2分探索で抑制できる最大のコストを計算する。
    int ma=(1<<30)-1;
    for(int i=29;i>=0;i--)
    {
        ll arg = ma - (1 << i);
        if(ok(arg))
        {
            ma-=1<<i;
            //cout << "ok:" << arg << endl;
        }
        else
        {
            //cout << "ng:" << arg << endl;
        }
    }
    cout<<ma<<endl;
    
    //前後K時間中は無理なのでNGとする
    ll pre=-1LL<<40;
    for(int i = 0;i < N;i++) {
        if(D[i]>ma) pre = T[i];
        else if(T[i]-pre<K) NG[i]=1;
    }
    pre=1LL<<40;
    for(int i=N-1;i>=0;i--) {
        if(D[i]>ma) pre = T[i];
        else if(pre-T[i]<K) NG[i]=1;
    }
    
    ll sum=0;
    for(int i = 0;i < N;i++) {
        if(D[i]>ma) {
            //yukiを起こすので0にする
            D[i]=0;
        }
        else
        {
            sum+=D[i];
            if(NG[i])
            {
                //のちのdpではコスト0としてカウントする
                D[i]=0;
            }
        }
    }
    
    ll tma=0;
    int x=0;
    for(int i = 0;i < N;i++)
    {
        //尺取り法
        //ll tma = 0;
        //for(int j = 0;j < i;j++)
        //{
        //    if(T[i]-T[j] >= K)
        //    {
        //        t = max(t, dp[j]);
        //    }
        //}
        while(T[i]-T[x]>=K)
        {
            tma=max(tma,dp[x]);
            x++;
            //cout << "while:" << i << "," << tma << endl;
        }
        dp[i+1]=max(dp[i], tma+D[i]);
    }
    cout<<sum-dp[N]<<endl;
}

int main()
{
    solve();
    return 0;
}
0