結果
問題 | No.1330 Multiply or Divide |
ユーザー | o2c |
提出日時 | 2021-01-15 15:25:48 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,296 bytes |
コンパイル時間 | 13,244 ms |
コンパイル使用メモリ | 378,232 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-11-26 02:08:31 |
合計ジャッジ時間 | 15,681 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 11 ms
6,528 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,504 KB |
testcase_07 | RE | - |
testcase_08 | AC | 31 ms
7,496 KB |
testcase_09 | AC | 31 ms
7,424 KB |
testcase_10 | AC | 29 ms
7,492 KB |
testcase_11 | AC | 28 ms
7,680 KB |
testcase_12 | AC | 29 ms
7,632 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | AC | 1 ms
5,248 KB |
testcase_17 | RE | - |
testcase_18 | AC | 28 ms
7,680 KB |
testcase_19 | AC | 27 ms
7,808 KB |
testcase_20 | AC | 26 ms
7,680 KB |
testcase_21 | AC | 27 ms
7,680 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 | 0 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 1 ms
5,248 KB |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 21 ms
6,144 KB |
testcase_35 | AC | 6 ms
5,248 KB |
testcase_36 | AC | 19 ms
5,632 KB |
testcase_37 | AC | 16 ms
5,376 KB |
testcase_38 | AC | 11 ms
5,248 KB |
testcase_39 | AC | 7 ms
5,248 KB |
testcase_40 | AC | 8 ms
5,248 KB |
testcase_41 | AC | 5 ms
5,248 KB |
testcase_42 | AC | 15 ms
5,248 KB |
testcase_43 | AC | 18 ms
5,504 KB |
testcase_44 | RE | - |
testcase_45 | RE | - |
ソースコード
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 { if x * c[0] > m { y += 1; break; } 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)); }