結果
問題 | No.1330 Multiply or Divide |
ユーザー | o2c |
提出日時 | 2021-01-15 15:24:44 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,205 bytes |
コンパイル時間 | 11,436 ms |
コンパイル使用メモリ | 383,440 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-11-26 02:06:46 |
合計ジャッジ時間 | 14,078 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 12 ms
6,656 KB |
testcase_02 | WA | - |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 8 ms
5,632 KB |
testcase_07 | WA | - |
testcase_08 | AC | 30 ms
7,492 KB |
testcase_09 | AC | 32 ms
7,424 KB |
testcase_10 | AC | 30 ms
7,492 KB |
testcase_11 | AC | 29 ms
7,680 KB |
testcase_12 | AC | 31 ms
7,500 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 1 ms
5,248 KB |
testcase_17 | WA | - |
testcase_18 | AC | 29 ms
7,680 KB |
testcase_19 | AC | 28 ms
7,680 KB |
testcase_20 | AC | 28 ms
7,808 KB |
testcase_21 | AC | 28 ms
7,808 KB |
testcase_22 | AC | 28 ms
7,680 KB |
testcase_23 | AC | 13 ms
7,168 KB |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | AC | 1 ms
5,248 KB |
testcase_26 | AC | 1 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 1 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 0 ms
5,248 KB |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 23 ms
6,400 KB |
testcase_35 | AC | 6 ms
5,248 KB |
testcase_36 | AC | 19 ms
5,632 KB |
testcase_37 | AC | 17 ms
5,248 KB |
testcase_38 | AC | 11 ms
5,248 KB |
testcase_39 | AC | 8 ms
5,248 KB |
testcase_40 | AC | 9 ms
5,248 KB |
testcase_41 | AC | 5 ms
5,248 KB |
testcase_42 | AC | 16 ms
5,248 KB |
testcase_43 | AC | 19 ms
5,632 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
ソースコード
use std::cmp::*; #[allow(dead_code)] mod scanner { use std; use std::io::Read; use std::str::FromStr; use std::str::SplitWhitespace; pub struct Scanner<'a> { it: SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next<T: FromStr>(&mut self) -> T { match self.it.next().unwrap().parse::<T>() { Ok(v) => v, _ => panic!("Scanner error"), } } pub fn next_chars(&mut self) -> Vec<char> { self.next::<String>().chars().collect() } pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> { (0..len).map(|_| self.next()).collect() } } pub fn read_string() -> String { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s } } trait Monoid { fn id() -> Self; fn f(a: Self, b: Self) -> Self; } #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] enum MinInt { Val(i64), Maximal, } #[allow(dead_code)] impl MinInt { fn unwrap(self) -> i64 { if let Self::Val(x) = self { x } else { panic!(); } } fn map<F>(self, f: F) -> Self where F: Fn(i64) -> i64, { if let Self::Val(x) = self { Self::Val(f(x)) } else { Self::Maximal } } fn map2<F>(self, b: Self, f: F) -> Self where F: Fn(i64, i64) -> i64, { match (self, b) { (Self::Val(x), Self::Val(y)) => Self::Val(f(x, y)), _ => Self::Maximal, } } fn get_or(self, default: i64) -> i64 { match self { Self::Val(x) => x, _ => default, } } } impl std::ops::Mul for MinInt { type Output = Self; fn mul(self, other: Self) -> Self { if self < other { self } else { other } } } impl Monoid for MinInt { fn id() -> Self { MinInt::Maximal } fn f(a: Self, b: Self) -> Self { a * b } } use MinInt::*; fn main() { let sc = scanner::read_string(); let mut sc = scanner::Scanner::new(&sc); let n: usize = sc.next(); let m: usize = sc.next(); let p: usize = sc.next(); let mut a = sc.next_vec::<usize>(n); let mut b = vec![]; let mut c = vec![]; for i in 0..n { if a[i] % p == 0 { while a[i] % p == 0 { a[i] /= p; } b.push(a[i]); } else { c.push(a[i]); } } b.sort(); c.sort(); b.reverse(); c.reverse(); let mut ans = Maximal; if !b.is_empty() && b[0] != 1 { let mut x = 1; let mut y = 0; while x <= m { x *= b[0]; y += 2; } ans = ans * Val(y); } if !c.is_empty() && c[0] != 1 { let mut x = 1; let mut y = 0; while x <= m { x *= c[0]; y += 1; } ans = ans * Val(y); } println!("{}", ans.get_or(-1)); }