結果

問題 No.1521 Playing Musical Chairs Alone
ユーザー StrorkisStrorkis
提出日時 2021-05-29 11:53:46
言語 Rust
(1.77.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 6,588 bytes
コンパイル時間 11,913 ms
コンパイル使用メモリ 387,792 KB
最終ジャッジ日時 2024-04-27 03:51:54
合計ジャッジ時間 12,557 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
error: format argument must be a string literal
 --> src/main.rs:8:34
  |
8 |                 Err(e) => panic!(e), 
  |                                  ^
  |
help: you might be missing a string literal to format with
  |
8 |                 Err(e) => panic!("{}", e), 
  |                                  +++++

error: could not compile `main` (bin "main") due to 1 previous error

ソースコード

diff #

mod io {
    pub fn scan<R: std::io::BufRead>(r: &mut R) -> Vec<u8> {
        let mut res = Vec::new();
        loop {
            let buf = match r.fill_buf() {
                Ok(buf) => buf,
                Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
                Err(e) => panic!(e), 
            };
            let (done, used, buf) = {
                match buf.iter().position(u8::is_ascii_whitespace) {
                    Some(i) => (i > 0 || res.len() > 0, i + 1, &buf[..i]),
                    None => (buf.is_empty(), buf.len(), buf),
                }
            };
            res.extend_from_slice(buf);
            r.consume(used);
            if done { return res; }
        }
    }

    #[macro_export]
    macro_rules! scan {
        ($r:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| scan!($r, $t)).collect::<Vec<_>>()
        };
        ($r:expr, ($($t:tt),*)) => {
            ($(scan!($r, $t)),*)
        };
        ($r:expr, Usize1) => {
            scan!($r, usize) - 1
        };
        ($r:expr, Bytes) => {
            io::scan($r)
        };
        ($r:expr, String) => {
            String::from_utf8(scan!($r, Bytes)).unwrap()
        };
        ($r:expr, $t:ty) => {
            scan!($r, String).parse::<$t>().unwrap()
        };
    }

    #[macro_export]
    macro_rules! input {
        ($r: expr, $($($v:ident)* : $t:tt),* $(,)?) => {
            $(let $($v)* = scan!($r, $t);)*
        };
    }
}

pub mod mod_int {
    use std::{fmt, ops};

    #[derive(Clone, Copy, Debug)]
    pub struct ModInt(u64);

    impl ModInt {
        const MOD: u64 = 1_000_000_007;

        pub fn new(mut x: u64) -> Self {
            if x >= Self::MOD {
                x %= Self::MOD;
            }
            Self(x)
        }

        pub fn zero() -> Self {
            Self(0)
        }

        pub fn one() -> Self {
            Self(1)
        }
    }

    impl From<usize> for ModInt {
        fn from(x: usize) -> Self {
            Self::new(x as u64)
        }
    }

    impl From<i64> for ModInt {
        fn from(mut x: i64) -> Self {
            let m = Self::MOD as i64;
            if x.abs() >= m {
                x %= m;
            }
            if x < 0 {
                x += m
            }
            Self::new(x as u64)
        }
    }

    impl ops::Add for ModInt {
        type Output = Self;

        fn add(self, other: Self) -> Self {
            let mut x = self.0 + other.0;
            if x >= Self::MOD {
                x -= Self::MOD;
            }
            Self(x)
        }
    }

    impl ops::AddAssign for ModInt {
        fn add_assign(&mut self, other: Self) {
            *self = *self + other;
        }
    }

    impl ops::Sub for ModInt {
        type Output = Self;

        fn sub(mut self, other: Self) -> Self {
            if self.0 < other.0 {
                self.0 += Self::MOD;
            }
            Self(self.0 - other.0)
        }
    }

    impl ops::SubAssign for ModInt {
        fn sub_assign(&mut self, other: Self) {
            *self = *self - other;
        }
    }

    impl ops::Mul for ModInt {
        type Output = Self;

        fn mul(self, other: Self) -> Self {
            Self::new(self.0 * other.0)
        }
    }

    impl ops::MulAssign for ModInt {
        fn mul_assign(&mut self, other: Self) {
            *self = *self * other;
        }
    }

    impl fmt::Display for ModInt {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            write!(f, "{}", self.0)
        }
    }

    impl ModInt {
        pub fn pow(mut self, mut n: u64) -> Self {
            let mut res = Self::one();
            while n > 0 {
                if n & 1 == 1 {
                    res *= self;
                }
                self *= self;
                n >>= 1;
            }
            res
        }
        
        pub fn inv(self) -> Self {
            self.pow(Self::MOD - 2)
        }
    }
}

#[allow(dead_code)]
mod matrix {
    use std::ops::{Add, Mul};

    pub trait MatrixHelper: Add<Output = Self> + Mul<Output = Self> + Copy {
        fn zero() -> Self;
        fn one() -> Self;
    }
    
    #[derive(Clone)]
    pub struct Matrix<M> {
        n: usize, m: usize, a: Vec<Vec<M>>,
    }

    impl<M: MatrixHelper> Matrix<M> {
        pub fn new(n: usize, m: usize, a: Vec<Vec<M>>) -> Self {
            Matrix {
                n, m, a
            }
        }

        pub fn zero(n: usize, m: usize) -> Self {
            Matrix::new(n, m, vec![vec![M::zero(); m]; n])
        }

        pub fn identity(n: usize) -> Self {
            let mut res = Matrix::zero(n, n);
            for i in 0..n {
                res.a[i][i] = M::one();
            }
            res
        }

        pub fn get(&self, i: usize, j: usize) -> &M {
            &self.a[i][j]
        }

        pub fn mul(&self, other: &Self) -> Self {
            assert!(self.m == other.n);
            let mut res = Matrix::zero(self.n, other.m);
            for (res, b) in res.a.iter_mut().zip(self.a.iter()) {
                for (&b, c) in b.iter().zip(other.a.iter()) {
                    for (res, &c) in res.iter_mut().zip(c.iter()) {
                        *res = *res + b * c;
                    }
                }
            }
            res
        }

        pub fn pow(self, mut n: u64) -> Self {
            assert!(self.n == self.m);
            let mut res = Matrix::identity(self.n);
            let mut x = self.clone();
            while n > 0 {
                if n & 1 == 1 {
                    res = res.mul(&x);
                }
                x = x.mul(&x);
                n >>= 1;
            }
            res
        }
    }
}

use mod_int::ModInt;
use matrix::{Matrix, MatrixHelper};

impl MatrixHelper for ModInt {
    fn zero() -> Self {
        Self::zero()
    }

    fn one() -> Self {
        Self::one()
    }
}

fn run<R: std::io::BufRead, W: std::io::Write>(reader: &mut R, writer: &mut W) {
    input! {
        reader,
        n: usize, k: u64, l: usize,
    }
    
    let mut a = vec![vec![ModInt::zero(); n]; n];
    for c in 0..n {
        for x in 1..=l {
            a[c][(c + x) % n] = ModInt::one();
        }
    }

    let ans = Matrix::new(n, n, a).pow(k);
    for i in 0..n {
        writeln!(writer, "{}", ans.get(0, i)).ok();
    }
}

fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let ref mut reader = std::io::BufReader::new(stdin.lock());
    let ref mut writer = std::io::BufWriter::new(stdout.lock());
    run(reader, writer);
}
0