結果
問題 | No.2846 Birthday Cake |
ユーザー |
|
提出日時 | 2024-08-25 01:23:34 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 231 ms / 2,000 ms |
コード長 | 1,602 bytes |
コンパイル時間 | 12,905 ms |
コンパイル使用メモリ | 388,752 KB |
実行使用メモリ | 13,192 KB |
最終ジャッジ日時 | 2024-08-25 01:23:53 |
合計ジャッジ時間 | 18,606 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#[allow(unused_imports)]use std::cmp::*;#[allow(unused_imports)]use std::collections::*;use std::io::Read;#[allow(dead_code)]fn getline() -> String {let mut ret = String::new();std::io::stdin().read_line(&mut ret).ok().unwrap();ret}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;}}}#[allow(dead_code)]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)}// => 720720fn 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);}