提出 #75560174


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
#define int ll

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());

const int M = 200005;

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int n,q;
    cin >> n >> q;
    vector<int>a(n+1);
    vector<int>dp(M+5);
    for(int i = 1; i<=n; i++){
        cin >> a[i];
    }
    for(int i = 1; i<=M; i++){
        for(int j = 1; j<=min(n,i); j++){
            dp[i] = max(dp[i],dp[i-j] + a[j]);
        }
    }
    while(q--){
        int w;
        cin >> w;
        if(w <= M){
            cout << dp[w] << '\n';
        }
        else{
            int ans = 0;
            for(int i = 1; i<=n; i++){
                int amt = (w - M + i-1)/i + 5;
                ans = max(ans,dp[w - amt * i] + amt * a[i]);
            }
            cout << ans << '\n';
        }
    }
    return 0;
}

提出情報

提出日時
問題 N - ナップサック
ユーザ kevinyang
言語 C++23 (GCC 15.2.0)
得点 4
コード長 1100 Byte
結果 TLE
実行時間 > 2000 ms
メモリ 5060 KiB

ジャッジ結果

セット名 Sample Subtask All
得点 / 配点 0 / 0 4 / 4 0 / 2
結果
AC × 2
AC × 16
AC × 16
TLE × 31
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
Subtask 00_sample_00.txt, 00_sample_01.txt, 01_subtask_00.txt, 01_subtask_01.txt, 01_subtask_02.txt, 01_subtask_03.txt, 01_subtask_04.txt, 01_subtask_05.txt, 01_subtask_06.txt, 01_subtask_07.txt, 01_subtask_08.txt, 01_subtask_09.txt, 01_subtask_10.txt, 01_subtask_11.txt, 01_subtask_12.txt, 01_subtask_13.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_subtask_00.txt, 01_subtask_01.txt, 01_subtask_02.txt, 01_subtask_03.txt, 01_subtask_04.txt, 01_subtask_05.txt, 01_subtask_06.txt, 01_subtask_07.txt, 01_subtask_08.txt, 01_subtask_09.txt, 01_subtask_10.txt, 01_subtask_11.txt, 01_subtask_12.txt, 01_subtask_13.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 3 ms 4976 KiB
00_sample_01.txt AC 4 ms 5012 KiB
01_subtask_00.txt AC 235 ms 5056 KiB
01_subtask_01.txt AC 234 ms 5012 KiB
01_subtask_02.txt AC 235 ms 4984 KiB
01_subtask_03.txt AC 174 ms 5048 KiB
01_subtask_04.txt AC 175 ms 5012 KiB
01_subtask_05.txt AC 174 ms 5012 KiB
01_subtask_06.txt AC 173 ms 5048 KiB
01_subtask_07.txt AC 173 ms 4972 KiB
01_subtask_08.txt AC 173 ms 4972 KiB
01_subtask_09.txt AC 169 ms 4960 KiB
01_subtask_10.txt AC 173 ms 5060 KiB
01_subtask_11.txt AC 173 ms 5028 KiB
01_subtask_12.txt AC 173 ms 4908 KiB
01_subtask_13.txt AC 173 ms 5028 KiB
02_random_00.txt TLE > 2000 ms 4908 KiB
02_random_01.txt TLE > 2000 ms 5000 KiB
02_random_02.txt TLE > 2000 ms 5028 KiB
02_random_03.txt TLE > 2000 ms 5012 KiB
02_random_04.txt TLE > 2000 ms 4976 KiB
02_random_05.txt TLE > 2000 ms 5012 KiB
02_random_06.txt TLE > 2000 ms 5012 KiB
02_random_07.txt TLE > 2000 ms 4960 KiB
02_random_08.txt TLE > 2000 ms 5060 KiB
02_random_09.txt TLE > 2000 ms 4984 KiB
02_random_10.txt TLE > 2000 ms 4976 KiB
02_random_11.txt TLE > 2000 ms 5012 KiB
02_random_12.txt TLE > 2000 ms 5060 KiB
02_random_13.txt TLE > 2000 ms 4972 KiB
02_random_14.txt TLE > 2000 ms 5060 KiB
02_random_15.txt TLE > 2000 ms 5012 KiB
02_random_16.txt TLE > 2000 ms 5012 KiB
02_random_17.txt TLE > 2000 ms 5012 KiB
02_random_18.txt TLE > 2000 ms 5012 KiB
02_random_19.txt TLE > 2000 ms 4976 KiB
02_random_20.txt TLE > 2000 ms 4976 KiB
02_random_21.txt TLE > 2000 ms 4908 KiB
02_random_22.txt TLE > 2000 ms 5048 KiB
02_random_23.txt TLE > 2000 ms 4972 KiB
02_random_24.txt TLE > 2000 ms 4948 KiB
02_random_25.txt TLE > 2000 ms 5048 KiB
02_random_26.txt TLE > 2000 ms 5060 KiB
02_random_27.txt TLE > 2000 ms 4972 KiB
02_random_28.txt TLE > 2000 ms 5056 KiB
02_random_29.txt TLE > 2000 ms 4976 KiB
02_random_30.txt TLE > 2000 ms 5028 KiB