結果

問題 No.634 硬貨の枚数1
ユーザー phsplsphspls
提出日時 2023-01-29 04:22:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 628 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 146,860 KB
実行使用メモリ 41,056 KB
最終ジャッジ日時 2023-09-11 13:42:03
合計ジャッジ時間 11,600 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 8 ms
6,032 KB
testcase_15 AC 168 ms
34,888 KB
testcase_16 AC 46 ms
15,992 KB
testcase_17 AC 64 ms
19,524 KB
testcase_18 AC 48 ms
15,960 KB
testcase_19 AC 135 ms
31,296 KB
testcase_20 AC 176 ms
36,704 KB
testcase_21 AC 203 ms
39,276 KB
testcase_22 AC 162 ms
34,144 KB
testcase_23 AC 42 ms
14,748 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 4 ms
4,384 KB
testcase_35 AC 31 ms
12,368 KB
testcase_36 AC 104 ms
24,360 KB
testcase_37 AC 58 ms
17,308 KB
testcase_38 AC 8 ms
5,720 KB
testcase_39 AC 172 ms
33,328 KB
testcase_40 AC 99 ms
23,436 KB
testcase_41 AC 86 ms
21,292 KB
testcase_42 AC 156 ms
31,816 KB
testcase_43 AC 42 ms
14,220 KB
testcase_44 AC 1 ms
4,384 KB
testcase_45 AC 1 ms
4,384 KB
testcase_46 AC 8 ms
5,784 KB
testcase_47 AC 216 ms
41,056 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 7 ms
5,728 KB
testcase_50 AC 226 ms
41,048 KB
testcase_51 AC 8 ms
5,784 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 1 ms
4,384 KB
testcase_55 AC 207 ms
40,484 KB
testcase_56 AC 197 ms
40,068 KB
testcase_57 AC 184 ms
39,728 KB
testcase_58 AC 183 ms
39,280 KB
testcase_59 AC 194 ms
39,276 KB
testcase_60 AC 190 ms
38,740 KB
testcase_61 AC 196 ms
39,460 KB
testcase_62 AC 194 ms
39,012 KB
testcase_63 AC 204 ms
39,728 KB
testcase_64 AC 187 ms
39,540 KB
testcase_65 AC 172 ms
38,692 KB
testcase_66 AC 201 ms
40,312 KB
testcase_67 AC 190 ms
39,808 KB
testcase_68 AC 189 ms
39,800 KB
testcase_69 AC 186 ms
39,804 KB
testcase_70 AC 195 ms
39,464 KB
testcase_71 AC 182 ms
39,528 KB
testcase_72 AC 189 ms
38,968 KB
testcase_73 AC 196 ms
38,668 KB
testcase_74 AC 194 ms
38,488 KB
testcase_75 AC 190 ms
38,404 KB
testcase_76 AC 1 ms
4,380 KB
testcase_77 AC 16 ms
9,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();

    let mut dp = vec![3; n+1];
    dp[n] = 0;
    let mut deque = VecDeque::new();
    for i in 1.. {
        let val = i * (i+1) / 2;
        if val > n { break; }
        dp[n - val] = 1;
        deque.push_back(n - val);
    }
    while let Some(v) = deque.pop_front() {
        for i in 1.. {
            let val = i * (i + 1) / 2;
            if val > v { break; }
            dp[v - val] = dp[v - val].min(2);
        }
    }
    println!("{}", dp[0]);
}
0