提出 #68156235


ソースコード 拡げる

#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops,fast-math")
//#pragma GCC target("avx2,fma")
using namespace std;
typedef long long ll;
int n,p[10010],a[10010],b[10010],q,t,dp[10010][1001],sm[10010];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> p[i] >> a[i] >> b[i];
        sm[i]=sm[i-1]+b[i];
    }
    for(int i=0;i<=1000;i++) dp[n+1][i]=i;
    for(int i=n;i;i--) {
        int kk=p[i], aa=a[i], bb=b[i];
        for(int j=0;j<=kk;j++) dp[i][j]=dp[i+1][j+aa];
        for(int j=kk+1;j<1001;j++) dp[i][j]=dp[i+1][max(0,j-bb)];
    }
    //for(int i=1;i<=n;i++) cout << sm[i] << " ";
    for(cin >> q;q--;) {
        cin >> t;
        if(t<1001) cout << dp[1][t] << "\n";
        else {
            int zz=lower_bound(&sm[0],&sm[n+1],t-1000)-&sm[0];
           // cout << zz << " ";
            if(zz==n+1) cout << t-sm[n] << "\n";
            else cout << dp[zz+1][t-sm[zz]] << "\n";
        }
    }
}

提出情報

提出日時
問題 D - Takahashi's Expectation
ユーザ Hakuaa_2
言語 C++ 20 (gcc 12.2)
得点 425
コード長 1025 Byte
結果 AC
実行時間 83 ms
メモリ 44784 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 3
AC × 30
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3420 KiB
00_sample_01.txt AC 1 ms 3436 KiB
00_sample_02.txt AC 1 ms 3384 KiB
01_random_03.txt AC 82 ms 44760 KiB
01_random_04.txt AC 82 ms 44708 KiB
01_random_05.txt AC 81 ms 44752 KiB
01_random_06.txt AC 82 ms 44760 KiB
01_random_07.txt AC 83 ms 44784 KiB
01_random_08.txt AC 81 ms 44724 KiB
01_random_09.txt AC 81 ms 44712 KiB
01_random_10.txt AC 82 ms 44672 KiB
01_random_11.txt AC 81 ms 44676 KiB
01_random_12.txt AC 82 ms 44716 KiB
01_random_13.txt AC 82 ms 44748 KiB
01_random_14.txt AC 82 ms 44740 KiB
01_random_15.txt AC 82 ms 44664 KiB
01_random_16.txt AC 28 ms 18172 KiB
01_random_17.txt AC 27 ms 4060 KiB
01_random_18.txt AC 74 ms 35336 KiB
01_random_19.txt AC 17 ms 14716 KiB
01_random_20.txt AC 26 ms 26840 KiB
01_random_21.txt AC 68 ms 21992 KiB
01_random_22.txt AC 61 ms 6380 KiB
01_random_23.txt AC 36 ms 6012 KiB
01_random_24.txt AC 82 ms 44700 KiB
01_random_25.txt AC 83 ms 44748 KiB
01_random_26.txt AC 80 ms 44764 KiB
01_random_27.txt AC 81 ms 44728 KiB
01_random_28.txt AC 81 ms 44752 KiB
01_random_29.txt AC 83 ms 44656 KiB