結果
| 問題 |
No.1809 Divide NCK
|
| ユーザー |
fukafukatani
|
| 提出日時 | 2022-01-15 16:55:09 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,790 bytes |
| コンパイル時間 | 12,539 ms |
| コンパイル使用メモリ | 380,952 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-21 19:15:43 |
| 合計ジャッジ時間 | 14,050 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 24 RE * 1 |
コンパイルメッセージ
warning: unused variable: `i`
--> src/main.rs:25:9
|
25 | for i in 0..=50 {
| ^ help: if this is intentional, prefix it with an underscore: `_i`
|
= note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;
#[allow(unused_macros)]
macro_rules! debug {
($($e:expr),*) => {
#[cfg(debug_assertions)]
$({
let (e, mut err) = (stringify!($e), std::io::stderr());
writeln!(err, "{} = {:?}", e, $e).unwrap()
})*
};
}
fn main() {
let v = read_vec::<i128>();
let (n, k, m) = (v[0], v[1], v[2]);
let mut ans = 0;
let mut x = 1;
let mut m2 = m;
for i in 0..=50 {
if m2 > n {
break;
}
let c1 = count(k, m2);
let c2 = count(n, m2);
let c3 = count(n - k, m2);
let d1 = (0..=50).map(|x| c2[x] - c3[x]).collect::<Vec<_>>();
let cc = (1..=50).map(|x| c1[x] * x as i128).sum::<i128>();
let dc = (1..=50).map(|x| d1[x] * x as i128).sum::<i128>();
if dc > cc {
ans = x;
}
m2 *= m;
x += 1;
}
println!("{}", ans);
}
fn count(k: i128, m: i128) -> Vec<i128> {
let mut start = 0;
let mut coef = 1;
while coef * m <= k {
start += 1;
coef *= m;
}
let mut coef2 = coef;
let mut start2 = start;
let mut count2 = 0;
let mut ret = vec![0; 51];
while coef2 >= 1 {
let cur_count = k / coef2 - count2;
ret[start2 as usize] = cur_count;
count2 += cur_count;
coef2 /= m;
start2 -= 1;
}
ret
}
fn read<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
read::<String>()
.split_whitespace()
.map(|e| e.parse().ok().unwrap())
.collect()
}
fukafukatani