結果
問題 | No.1879 How many matchings? |
ユーザー |
|
提出日時 | 2022-03-18 22:48:54 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,501 bytes |
コンパイル時間 | 11,958 ms |
コンパイル使用メモリ | 389,180 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-03 07:47:42 |
合計ジャッジ時間 | 12,817 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 WA * 8 |
ソースコード
#[allow(unused_imports)]use std::cmp::*;#[allow(unused_imports)]use std::collections::*;use std::io::Read;#[allow(dead_code)]fn getline() -> String {let mut ret = String::new();std::io::stdin().read_line(&mut ret).ok().unwrap();ret}fn get_word() -> String {let stdin = std::io::stdin();let mut stdin=stdin.lock();let mut u8b: [u8; 1] = [0];loop {let mut buf: Vec<u8> = Vec::with_capacity(16);loop {let res = stdin.read(&mut u8b);if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {break;} else {buf.push(u8b[0]);}}if buf.len() >= 1 {let ret = String::from_utf8(buf).unwrap();return ret;}}}#[allow(dead_code)]fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }fn squmul(a: &[Vec<i64>], b: &[Vec<i64>], mo: i64) -> Vec<Vec<i64>> {let n = a.len();let mut ret = vec![vec![0; n]; n];for i in 0..n {for j in 0..n {for k in 0..n {ret[i][k] += a[i][j] * b[j][k];ret[i][k] %= mo;}}}ret}fn squpow(a: &[Vec<i64>], mut e: i64, mo: i64) -> Vec<Vec<i64>> {let n = a.len();let mut sum = vec![vec![0; n]; n];for i in 0..n { sum[i][i] = 1; }let mut cur = a.to_vec();while e > 0 {if e % 2 == 1 {sum = squmul(&sum, &cur, mo);}cur = squmul(&cur, &cur, mo);e /= 2;}sum}fn solve() {let n: i64 = get();const MOD: i64 = 1_000_000_007;let mut mat;if n % 2 == 0 {mat = vec![vec![0; 4]; 4];for i in 0..2 {mat[i][2 * i + 1] += 1;mat[2 + i][2 * i] += 1;}mat[1][0] += 1;} else {mat = vec![vec![0; 8]; 8];for j in 0..2 {for i in 0..2 {mat[4 * j + i][4 * j + 2 * i + 1] += 1;mat[4 * j + 2 + i][4 * j + 2 * i] += 1;}mat[4 * j + 1][4 * j] += 1;}mat[0][4] += 1;}let pw = squpow(&mat, n, MOD);let ans = pw[0][4 * (n % 2) as usize];println!("{}", ans);}fn main() {// In order to avoid potential stack overflow, spawn a new thread.let stack_size = 104_857_600; // 100 MBlet thd = std::thread::Builder::new().stack_size(stack_size);thd.spawn(|| solve()).unwrap().join().unwrap();}