結果
問題 | No.1711 Divide LCM |
ユーザー | akakimidori |
提出日時 | 2021-10-15 22:38:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,993 bytes |
コンパイル時間 | 11,778 ms |
コンパイル使用メモリ | 399,232 KB |
実行使用メモリ | 57,136 KB |
最終ジャッジ日時 | 2024-09-17 17:49:35 |
合計ジャッジ時間 | 19,873 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 4 ms
5,376 KB |
testcase_04 | AC | 5 ms
5,376 KB |
testcase_05 | AC | 13 ms
5,376 KB |
testcase_06 | AC | 6 ms
5,376 KB |
testcase_07 | AC | 11 ms
5,376 KB |
testcase_08 | AC | 6 ms
5,376 KB |
testcase_09 | AC | 24 ms
5,436 KB |
testcase_10 | AC | 6 ms
5,376 KB |
testcase_11 | AC | 31 ms
6,528 KB |
testcase_12 | AC | 7 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 5 ms
5,376 KB |
testcase_15 | AC | 5 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | WA | - |
testcase_18 | AC | 57 ms
20,608 KB |
testcase_19 | AC | 59 ms
20,608 KB |
testcase_20 | AC | 56 ms
20,480 KB |
testcase_21 | AC | 110 ms
25,600 KB |
testcase_22 | AC | 321 ms
51,488 KB |
testcase_23 | AC | 307 ms
57,136 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 87 ms
16,796 KB |
testcase_27 | AC | 92 ms
16,736 KB |
testcase_28 | AC | 86 ms
16,384 KB |
testcase_29 | AC | 3 ms
5,376 KB |
testcase_30 | WA | - |
testcase_31 | AC | 3 ms
5,376 KB |
testcase_32 | AC | 149 ms
22,016 KB |
testcase_33 | AC | 87 ms
22,144 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 89 ms
27,008 KB |
testcase_39 | AC | 112 ms
24,576 KB |
testcase_40 | AC | 3 ms
5,376 KB |
testcase_41 | AC | 3 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 3 ms
5,376 KB |
ソースコード
// ---------- begin next_permutation ---------- fn next_permutation<T: Ord>(a: &mut [T]) -> bool { a.windows(2).rposition(|a| a[0] < a[1]).map_or(false, |x| { let y = a.iter().rposition(|b| a[x] < *b).unwrap(); a.swap(x, y); a[(x + 1)..].reverse(); true }) } // ---------- end next_permutation ---------- // ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::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 { self.it.next().unwrap().parse::<T>().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec<u8> { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec<char> { self.it.next().unwrap().chars().collect() } pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) { let n: usize = sc.next(); let mut dp = vec![0; 1000000 + 1]; let mut a = vec![]; for _ in 0..n { let m: usize = sc.next(); let mut p = vec![(0usize, 0usize); m]; for p in p.iter_mut() { p.0 = sc.next(); p.1 = sc.next(); dp[p.0] = dp[p.0].max(p.1); } a.push(p); } let mut cond = vec![]; for i in 0..dp.len() { if dp[i] > 0 { cond.push(i); } } for a in a.iter() { if a.len() == cond.len() && a.iter().all(|p| p.1 == dp[p.0]) { writeln!(out, "-1").ok(); return; } } let mut ban = std::collections::BTreeSet::new(); for a in a.iter() { let mut p = vec![]; for a in a.iter() { if dp[a.0] == a.1 { p.push(a.0); } } ban.insert(p); } for i in 1.. { let mut next = vec![]; for ban in ban.iter() { if ban.len() > i { let mut p = ban.clone(); p.remove(i - 1); next.push(p); } } if next.len() == 0 { break; } ban.extend(next); } for k in 2.. { let mut test = vec![0; cond.len()]; for t in test.iter_mut().rev().take(k) { *t = 1; } while { let mut x = vec![]; for (i, t) in test.iter().enumerate() { if *t > 0 { x.push(cond[i]); } } if !ban.contains(&x) { let mut ans = vec![vec![]; k]; for a in a { for (ans, &x) in ans.iter_mut().zip(&x) { if !a.contains(&(x, dp[x])) { ans.push(a.iter().fold(1, |s, a| s * a.0.pow(a.1 as u32))); break; } } } writeln!(out, "{}", ans.len()).ok(); for ans in ans { write!(out, "{}", ans.len()).ok(); for a in ans { write!(out, " {}", a).ok(); } writeln!(out).ok(); } return; } next_permutation(&mut test) } {} } }