結果
問題 |
No.2709 1975 Powers
|
ユーザー |
|
提出日時 | 2025-05-29 15:27:05 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,226 bytes |
コンパイル時間 | 11,617 ms |
コンパイル使用メモリ | 388,236 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-05-29 15:27:39 |
合計ジャッジ時間 | 32,981 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 8 WA * 16 TLE * 1 |
コンパイルメッセージ
warning: trait `DisplayVec` is never used --> src/main.rs:19:7 | 19 | trait DisplayVec<T> { | ^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
#[allow(unused_imports)] use proconio::{ fastout, input, marker::{Chars, Usize1}, }; #[allow(unused_imports)] use std::cmp::{max, min}; #[allow(unused_imports)] use std::collections::{HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::fmt::Debug; #[allow(unused_imports)] use std::iter::{Flatten, FromIterator}; #[allow(unused_imports)] use std::ops::Index; #[allow(unused_imports)] use std::vec::IntoIter; trait DisplayVec<T> { fn print(&self, sep: &str); } impl<T> DisplayVec<T> for Vec<T> where T: ToString, { fn print(&self, sep: &str) { println!( "{}", self.iter() .map(std::string::ToString::to_string) .collect::<Vec<_>>() .join(sep) ) } } #[allow(dead_code)] fn print_chars(input_: &[char]) { println!("{}", &input_.iter().collect::<String>()) } #[allow(dead_code)] fn ctoi(c: &char) -> i32 { *c as i32 - 48 } #[allow(dead_code)] #[allow(non_snake_case)] fn YESNO(res: bool) { if res { println!("YES") } else { println!("NO") } } #[allow(dead_code)] #[allow(non_snake_case)] fn YesNo(res: bool) { if res { println!("Yes") } else { println!("No") } } #[allow(dead_code)] fn yesno(res: bool) { if res { println!("yes") } else { println!("no") } } #[allow(unused_macros)] macro_rules! input_arrays_with_len { ($e:expr, $t:ty) => { (0..$e) .map(|_| { input! { l: u32, nums: [$t; l] } nums }) .collect_vec() }; } fn mod_pow(num: i64, index_: i64, mod_: i64) -> i64 { if index_ == 0 { return 1; } if index_ % 2 == 0 { return mod_pow((num * num) % mod_, index_ / 2, mod_); } else { return num * mod_pow(num, index_ - 1, mod_) % mod_; } } fn combinations<T, F>( origin: &Vec<Vec<T>>, cur_idx: usize, cur_rest: usize, cur_array: &mut Vec<usize>, func: &F, ) -> i64 where F: Fn(&Vec<Vec<T>>, &Vec<usize>) -> bool, { if cur_rest == 0 { return func(origin, &cur_array) as i64; } if cur_idx + cur_rest > origin.len() { return 0; } let mut ans = combinations(origin, cur_idx + 1, cur_rest, cur_array, func); if cur_rest > 0 { cur_array.push(cur_idx); ans += combinations(origin, cur_idx + 1, cur_rest - 1, cur_array, func); cur_array.pop(); } ans } fn main() { input! { n: usize, p: i64, q: i64, a: [i64; n], } let divisors = [10, 9, 7, 5]; let a_mod = a .iter() .map(|&a_elm| { divisors .iter() .map(move |&div_| mod_pow(div_, a_elm, p)) .collect::<Vec<i64>>() }) .collect::<Vec<_>>(); let mut cur = vec![]; let ctr = combinations(&a_mod, 0, 4, &mut cur, &|mods, array| { let v = array .iter() .enumerate() .map(|(idx, &elm)| mods[elm as usize][idx]) .fold(0, |sum, x| (sum + x) % p); v == q }); println!("{}", ctr); }