結果

問題 No.2846 Birthday Cake
ユーザー koba-e964koba-e964
提出日時 2024-08-25 01:24:19
言語 Rust
(1.77.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 1,433 bytes
コンパイル時間 12,902 ms
コンパイル使用メモリ 391,012 KB
実行使用メモリ 13,176 KB
最終ジャッジ日時 2024-08-25 01:24:38
合計ジャッジ時間 18,004 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
10,596 KB
testcase_01 AC 35 ms
12,612 KB
testcase_02 AC 155 ms
13,068 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 17 ms
7,296 KB
testcase_05 AC 161 ms
12,944 KB
testcase_06 AC 172 ms
13,064 KB
testcase_07 AC 176 ms
12,944 KB
testcase_08 AC 182 ms
12,940 KB
testcase_09 AC 200 ms
13,068 KB
testcase_10 AC 202 ms
13,064 KB
testcase_11 AC 212 ms
13,068 KB
testcase_12 AC 140 ms
13,172 KB
testcase_13 AC 168 ms
13,176 KB
testcase_14 AC 85 ms
13,124 KB
testcase_15 AC 129 ms
13,076 KB
testcase_16 AC 159 ms
13,124 KB
testcase_17 AC 211 ms
13,052 KB
testcase_18 AC 227 ms
12,944 KB
testcase_19 AC 30 ms
13,140 KB
testcase_20 AC 56 ms
13,152 KB
testcase_21 AC 14 ms
7,168 KB
testcase_22 AC 80 ms
13,116 KB
testcase_23 AC 66 ms
13,176 KB
testcase_24 AC 187 ms
13,176 KB
testcase_25 AC 8 ms
7,680 KB
testcase_26 AC 85 ms
13,060 KB
testcase_27 AC 110 ms
13,164 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 129 ms
13,084 KB
testcase_30 AC 13 ms
7,168 KB
testcase_31 AC 59 ms
13,116 KB
testcase_32 AC 162 ms
12,980 KB
testcase_33 AC 186 ms
13,176 KB
testcase_34 AC 125 ms
12,996 KB
testcase_35 AC 137 ms
13,116 KB
testcase_36 AC 169 ms
13,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

// https://yukicoder.me/problems/no/2846 (3)
// irb(main):009> [24,22,21,20,18,16,15,14,13,12,11,10,9,8,7,6,5].reduce{|a,b|a.lcm(b)}
// => 720720
// 素数 23, 19, 17 だけ特別扱いして、あとは幅 720720 の DP で解く。
fn main() {
    let k: usize = get();
    let n: usize = get();
    const W: usize = 720_720;
    let prs = [23, 19, 17];
    let mut dp = vec![0i64; W + 1];
    dp[0] = 1;
    for _ in 0..k {
        let mut ep = vec![0; W + 1];
        for i in 1..n + 1 {
            if W % i != 0 { continue; }
            let x = W / i;
            for j in x..W + 1 {
                ep[j] += dp[j - x];
            }
        }
        dp = ep;
    }
    let mut ans = dp[W];
    for &p in &prs {
        if k == p {
            ans += 1;
        }
    }
    println!("{}", ans);
}
0