結果

問題 No.634 硬貨の枚数1
ユーザー @abcde@abcde
提出日時 2019-05-11 12:24:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,345 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 150,380 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 18:06:52
合計ジャッジ時間 4,733 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 3 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 3 ms
4,380 KB
testcase_45 WA -
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 3 ms
4,376 KB
testcase_48 AC 4 ms
4,376 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 2 ms
4,380 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL LIMIT = 4500;  // 上限を, 4500 * 4501 / 2 = 10127250 に 変更.

int main() {
    
    // 1. 入力情報取得.
    LL N;
    cin >> N;
    
    // 2. 硬貨準備.
    map<LL, LL> m;
    for(int i = 0; i < LIMIT; i++){
        LL c = (i + 1) * (i + 2) / 2;
        m[c]++;
    }
    // for(int i = 0; i < LIMIT; i++) cout << coins[i] << endl;
    
    // 3. 支払う硬貨をカウント.
    // i円以下の最小支払い回数を計算していく.
    // -> 10000まで調べると, 1 or 2 or 3 のいずれかだった.
    // なので, 以下のようにロジック変更.
    // ① map に ある … 1回.
    // ② map を巡回しペアが見つかった … 2回.
    // ③ 上記以外 … 3回.
    
    // 3-1. 条件③ を 設定.
    int ans = 3;
    
    // 3-2. 条件② の チェック.
    for(auto &p : m){
        LL a = p.first;
        LL b = N - a;
        // ex.
        // N = 10001    ならば, a=5051    b=4950    の 2回. (4[ms])
        // N = 10000000 ならば, a=1719585 b=8280415 の 2回. (5[ms])
        if(m[b] > 0){
            ans = 2;
            break;
        }
    }
    
    // 3-3. 条件① の チェック.
    if(m[N] > 0) ans = 1;
    
    // 4. 出力.
    cout << ans << endl;
    return 0;
    
}
0