結果
問題 | No.2500 Products in a Range |
ユーザー | naut3 |
提出日時 | 2023-10-13 21:55:10 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,942 bytes |
コンパイル時間 | 13,625 ms |
コンパイル使用メモリ | 385,728 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-15 17:35:51 |
合計ジャッジ時間 | 26,086 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 8 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 165 ms
5,376 KB |
testcase_08 | AC | 374 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 703 ms
5,376 KB |
testcase_11 | AC | 926 ms
5,376 KB |
testcase_12 | AC | 310 ms
5,376 KB |
testcase_13 | AC | 9 ms
5,376 KB |
testcase_14 | AC | 780 ms
5,376 KB |
testcase_15 | AC | 27 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 83 ms
5,376 KB |
testcase_23 | AC | 6 ms
5,376 KB |
testcase_24 | AC | 45 ms
5,376 KB |
testcase_25 | AC | 1,412 ms
5,376 KB |
testcase_26 | AC | 1,404 ms
5,376 KB |
testcase_27 | AC | 1,410 ms
5,376 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 269 ms
5,376 KB |
testcase_34 | AC | 779 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 | AC | 1 ms
5,376 KB |
testcase_40 | AC | 1 ms
5,376 KB |
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 | AC | 126 ms
5,376 KB |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | AC | 1,400 ms
5,376 KB |
testcase_48 | AC | 1 ms
5,376 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 12 ms
5,376 KB |
testcase_52 | WA | - |
testcase_53 | AC | 3 ms
5,376 KB |
testcase_54 | AC | 1 ms
5,376 KB |
testcase_55 | AC | 2 ms
5,376 KB |
testcase_56 | AC | 4 ms
5,376 KB |
testcase_57 | AC | 26 ms
5,376 KB |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
ソースコード
#![allow(non_snake_case, unused_imports, unused_must_use)] use std::io::{self, prelude::*}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>() }; } let N = input!(usize); let L = input!(isize); let R = input!(isize); let mut A = input!(isize, N); A.sort(); let A = A; let mut ans = 1; for l in 0..N { let mut neg: std::collections::BTreeSet<(isize, usize)> = std::collections::BTreeSet::new(); let mut zer: std::collections::BTreeSet<(isize, usize)> = std::collections::BTreeSet::new(); let mut pos: std::collections::BTreeSet<(isize, usize)> = std::collections::BTreeSet::new(); let a = A[l]; if a < 0 { neg.insert((a, l)); } else if a == 0 { zer.insert((a, l)); } else { pos.insert((a, l)); } if l + 1 < N { let a = A[l + 1]; if a < 0 { neg.insert((a, l + 1)); } else if a == 0 { zer.insert((a, l + 1)); } else { pos.insert((a, l + 1)); } } for r in l + 2..=N { if r - l > ans { // [l, r) は ok か? let mut can_update = true; let mut cand = std::collections::BTreeSet::new(); let n1 = neg.range(..).next(); match n1 { Some(&(v, i)) => { cand.insert((v, i)); let n2 = neg.range((v, i + 1)..).next(); match n2 { Some(&(v2, i2)) => { cand.insert((v2, i2)); } None => {} } } None => {} } let nn1 = neg.range(..).next_back(); match nn1 { Some(&(v, i)) => { cand.insert((v, i)); let n2 = neg.range(..(v, i)).next_back(); match n2 { Some(&(v2, i2)) => { cand.insert((v2, i2)); } None => {} } } None => {} } let z1 = zer.range(..).next(); match z1 { Some(&(v, i)) => { cand.insert((v, i)); } None => {} } let p1 = pos.range(..).next(); match p1 { Some(&(v, i)) => { cand.insert((v, i)); let n2 = pos.range((v, i + 1)..).next(); match n2 { Some(&(v2, i2)) => { cand.insert((v2, i2)); } None => {} } } None => {} } let pp1 = pos.range(..).next_back(); match pp1 { Some(&(v, i)) => { cand.insert((v, i)); let n2 = pos.range(..(v, i)).next_back(); match n2 { Some(&(v2, i2)) => { cand.insert((v2, i2)); } None => {} } } None => {} } let C = cand.iter().map(|&(k, _)| k).collect::<Vec<_>>(); let mut m = 1 << 60; let mut M = -(1 << 60); let length = C.len(); for i in 0..length { for j in i + 1..length { m = std::cmp::min(m, C[i] * C[j]); M = std::cmp::max(M, C[i] * C[j]); } } if L <= m && R >= M { ans = std::cmp::max(ans, r - l); } else { can_update = false; } if !can_update { break; } } // A[r]を追加する. if r != N { let a = A[r]; if a < 0 { neg.insert((a, r)); } else if a == 0 { zer.insert((a, r)); } else { pos.insert((a, r)); } } } } writeln!(out, "{}", ans); } struct Scanner<R> { reader: R, buf_str: Vec<u8>, buf_iter: str::SplitWhitespace<'static>, } impl<R: BufRead> Scanner<R> { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token<T: str::FromStr>(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }