結果
問題 | No.2500 Products in a Range |
ユーザー | haihamabossu |
提出日時 | 2023-10-13 22:58:17 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,927 bytes |
コンパイル時間 | 13,808 ms |
コンパイル使用メモリ | 379,400 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 18:47:33 |
合計ジャッジ時間 | 16,069 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 4 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 15 ms
5,376 KB |
testcase_11 | AC | 19 ms
5,376 KB |
testcase_12 | AC | 7 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 20 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 6 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 19 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 18 ms
5,376 KB |
testcase_25 | AC | 28 ms
5,376 KB |
testcase_26 | AC | 27 ms
5,376 KB |
testcase_27 | AC | 27 ms
5,376 KB |
testcase_28 | AC | 5 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | WA | - |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 7 ms
5,376 KB |
testcase_34 | AC | 17 ms
5,376 KB |
testcase_35 | AC | 1 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 1 ms
5,376 KB |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
testcase_43 | AC | 1 ms
5,376 KB |
testcase_44 | RE | - |
testcase_45 | WA | - |
testcase_46 | RE | - |
testcase_47 | AC | 27 ms
5,376 KB |
testcase_48 | AC | 1 ms
5,376 KB |
testcase_49 | WA | - |
testcase_50 | AC | 1 ms
5,376 KB |
testcase_51 | AC | 2 ms
5,376 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 1 ms
5,376 KB |
testcase_54 | RE | - |
testcase_55 | RE | - |
testcase_56 | RE | - |
testcase_57 | RE | - |
testcase_58 | AC | 1 ms
5,376 KB |
testcase_59 | AC | 2 ms
5,376 KB |
testcase_60 | AC | 1 ms
5,376 KB |
ソースコード
pub mod scanner { pub struct Scanner { buf: Vec<String>, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next<T: std::str::FromStr>(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec<String> { source .split_whitespace() .rev() .map(String::from) .collect::<Vec<_>>() } } } use crate::scanner::Scanner; use std::io::Write; fn main() { let mut scanner = Scanner::new(); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); let t: usize = 1; for _ in 0..t { solve(&mut scanner, &mut out); } } fn solve(scanner: &mut Scanner, out: &mut std::io::BufWriter<std::io::StdoutLock>) { let n = scanner.next::<usize>(); let l = scanner.next::<isize>(); let r = scanner.next::<isize>(); let mut pos = vec![]; let mut neg = vec![]; let mut zero = 0usize; for _ in 0..n { let a = scanner.next::<isize>(); if a > 0 { pos.push(a); } else if a < 0 { neg.push(a); } else { zero += 1; } } pos.sort(); neg.sort(); if 0 <= l { let mut ans = 0; for a in [&pos, &neg] { let mut li: usize = !0; let mut ri: usize = 0; for i in 0..a.len() - 1 { let b = a[i] * a[i + 1]; if l <= b && b <= r { li = li.min(i); ri = ri.max(i + 1); } } let mut res = if li != !0 { ri - li + 1 } else { a.len().min(1) }; if l == 0 { res += zero; } ans = ans.max(res); } writeln!(out, "{}", ans).unwrap(); return; } if r <= 0 { let mut ans = 0; ans = ans.max(pos.len().min(1)); ans = ans.max(neg.len().min(1)); 'outer: for i in 0..pos.len() { for j in 0..neg.len() { let b = pos[i] * neg[j]; if l <= b && b <= r { ans = 2; break 'outer; } } } if r == 0 { ans += zero; } writeln!(out, "{}", ans).unwrap(); return; } let mut ans = 0; ans = ans.max(pos.len().min(1) + zero); ans = ans.max(neg.len().min(1) + zero); for i in 1..pos.len() { let b = pos[i - 1] * pos[i]; if l <= b && b <= r { ans = ans.max(i + 1 + zero); } } for j in 0..neg.len() - 1 { let b = neg[j] * neg[j + 1]; if l <= b && b <= r { ans = ans.max(neg.len() - j + zero); } } for i in 0..pos.len() { for j in 0..neg.len() { let mut ok = true; if i > 0 { let b = pos[i - 1] * pos[i]; ok &= l <= b && b <= r; } if j < neg.len() - 1 { let b = neg[j] * neg[j + 1]; ok &= l <= b && b <= r; } let b = pos[i] * neg[j]; ok &= l <= b && b <= r; if ok { ans = ans.max(i + 1 + neg.len() - j + zero); } } } writeln!(out, "{}", ans).unwrap(); }