結果

問題 No.617 Nafmo、買い出しに行く
ユーザー @abcde@abcde
提出日時 2019-02-24 15:17:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 719 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 1,487 ms
コンパイル使用メモリ 147,408 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 16:41:22
合計ジャッジ時間 19,249 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 700 ms
4,376 KB
testcase_01 AC 706 ms
4,376 KB
testcase_02 AC 701 ms
4,376 KB
testcase_03 AC 706 ms
4,380 KB
testcase_04 AC 706 ms
4,376 KB
testcase_05 AC 704 ms
4,380 KB
testcase_06 AC 710 ms
4,380 KB
testcase_07 AC 700 ms
4,380 KB
testcase_08 AC 709 ms
4,376 KB
testcase_09 AC 708 ms
4,380 KB
testcase_10 AC 700 ms
4,376 KB
testcase_11 AC 704 ms
4,380 KB
testcase_12 AC 702 ms
4,376 KB
testcase_13 AC 707 ms
4,380 KB
testcase_14 AC 706 ms
4,376 KB
testcase_15 AC 712 ms
4,376 KB
testcase_16 AC 704 ms
4,380 KB
testcase_17 AC 712 ms
4,376 KB
testcase_18 AC 711 ms
4,376 KB
testcase_19 AC 719 ms
4,380 KB
testcase_20 AC 709 ms
4,376 KB
testcase_21 AC 702 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
// const int LIMIT = 1 << 3;
// const int DIGIT = 3;
const int LIMIT = 1048576;
const int DIGIT = 20;

int main() {
    
    // 1. 入力情報取得.
    int N, K;
    cin >> N >> K;
    int A[DIGIT] = {};
    for(int i = 0; i < N; i++) cin >> A[i];
    
    // 2. 商品の重さの合計を計算.
    // N の 上限が, 2 の 20乗 = 1048576 なので, 全部確認できそう.
    int ans = 0;
    for(int i = 0; i < LIMIT; i++){
        // 2-1. i を 2進数表記.
        stringstream ss;
        ss << static_cast<std::bitset<DIGIT>>(i);
        string bit = ss.str();
        // cout << bit << endl;
        
        // 2-2. 各商品について, 以下のルールで読み替える.
        // bit の 各桁が 1 なら, 購入する
        // bit の 各桁が 0 なら, 購入しない
        int total = 0;
        for(int d = 0; d < DIGIT; d++) total += (bit[d] - '0') * A[d];
        
        // 2-3. 商品の重さの合計について, 最大値を更新.
        if(total <= K) ans = max(ans, total);
    
    }
    
    // 3. 出力 ~ 終了.
    cout << ans << endl;
    return 0;
    
}
0