結果

問題 No.1281 Cigarette Distribution
ユーザー fukafukatanifukafukatani
提出日時 2020-11-06 23:16:09
言語 Rust
(1.77.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,729 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 146,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 19:33:57
合計ジャッジ時間 4,107 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 73 ms
4,376 KB
testcase_13 AC 174 ms
4,380 KB
testcase_14 AC 126 ms
4,376 KB
testcase_15 AC 87 ms
4,380 KB
testcase_16 AC 109 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 292 ms
4,376 KB
testcase_19 AC 290 ms
4,380 KB
testcase_20 AC 289 ms
4,376 KB
testcase_21 AC 146 ms
4,376 KB
testcase_22 AC 180 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:26:9
   |
26 |     for i in 1..16 {
   |         ^ 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::<i64>();
    let (n, m) = (v[0], v[1]);
    println!("{}", n);
    for x in 2..m + 1 {
        println!("{}", solve(x, n));
    }

    for i in 1..16 {
        debug!(solve(4, i));
    }
}

fn solve(x: i64, n: i64) -> i64 {
    let mut n = n;
    if n <= x {
        return 0;
    }
    n -= x;
    let min_n = n / x;
    let mid_n = min_n + 1;
    let max_n = min_n + 2;

    let res = n % x;

    let big_int = 1000000000 + 7;
    if res == x - 1 {
        // debug!(mid_n, max_n, res);
        (mid_n * pow_m(max_n, res, big_int)) % big_int
    } else {
        // debug!(mid_n, max_n, res);
        (((min_n * pow_m(max_n, res + 1, big_int)) % big_int)
            * pow_m(mid_n, x - (res + 2), big_int))
            % big_int
    }
}

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_m(n: i64, mut p: i64, m: i64) -> i64 {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % m;
            p /= 2;
        } else {
            ret = ret * r % m;
            p -= 1;
        }
    }
    ret
}
0