結果

問題 No.1281 Cigarette Distribution
ユーザー fukafukatanifukafukatani
提出日時 2020-11-06 22:54:05
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,545 bytes
コンパイル時間 4,782 ms
コンパイル使用メモリ 142,084 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-29 19:23:45
合計ジャッジ時間 7,615 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,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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::<i64>();
    let (n, m) = (v[0], v[1]);
    println!("{}", n);
    for x in 2..m + 1 {
        let mut n = n;
        if n <= x {
            println!("0");
            continue;
        }
        n -= x;
        let min_n = n / x;
        let mid_n = min_n + 1;
        let max_n = min_n + 2;

        let res = n % x;

        let ans;
        // debug!(n, res);
        if res == x - 1 {
            ans = mid_n * pow(max_n, res);
        } else {
            ans = min_n * pow(max_n, res + 1) * pow(mid_n, x - (res - 2));
        }
        println!("{}", ans);
    }
}

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()
}

fn pow(n: i64, mut p: i64) -> i64 {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r;
            p /= 2;
        } else {
            ret = ret * r;
            p -= 1;
        }
    }
    ret
}
0