結果

問題 No.1809 Divide NCK
ユーザー fukafukatanifukafukatani
提出日時 2022-01-15 16:58:34
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,829 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 147,636 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-14 01:27:32
合計ジャッジ時間 2,746 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 0 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:25:9
   |
25 |     for i in 0..=100 {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![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..=100 {
        if m2 > n {
            break;
        }
        let c1 = count(k, m2);
        let c2 = count(n, m2);
        let c3 = count(n - k, m2);
        let d1 = (0..=100).map(|x| c2[x] - c3[x]).collect::<Vec<_>>();

        let cc = (1..=100).map(|x| c1[x] * x as i128).sum::<i128>();
        let dc = (1..=100).map(|x| d1[x] * x as i128).sum::<i128>();
        debug!((m2, cc, dc));
        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; 100 + 1];
    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()
}
0