結果
問題 | No.1711 Divide LCM |
ユーザー | akakimidori |
提出日時 | 2021-10-15 22:46:42 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,348 bytes |
コンパイル時間 | 11,964 ms |
コンパイル使用メモリ | 380,072 KB |
実行使用メモリ | 31,564 KB |
最終ジャッジ日時 | 2024-09-17 17:53:07 |
合計ジャッジ時間 | 26,761 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,756 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,812 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | AC | 10 ms
6,944 KB |
testcase_05 | AC | 59 ms
6,940 KB |
testcase_06 | AC | 16 ms
6,944 KB |
testcase_07 | AC | 44 ms
6,940 KB |
testcase_08 | AC | 11 ms
6,944 KB |
testcase_09 | AC | 99 ms
6,944 KB |
testcase_10 | AC | 20 ms
6,940 KB |
testcase_11 | AC | 137 ms
6,944 KB |
testcase_12 | AC | 22 ms
6,944 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 53 ms
21,288 KB |
testcase_19 | AC | 54 ms
21,408 KB |
testcase_20 | AC | 54 ms
21,276 KB |
testcase_21 | AC | 106 ms
28,196 KB |
testcase_22 | AC | 103 ms
9,932 KB |
testcase_23 | AC | 113 ms
11,996 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 2,259 ms
15,648 KB |
testcase_28 | AC | 1,906 ms
13,700 KB |
testcase_29 | AC | 5 ms
6,940 KB |
testcase_30 | WA | - |
testcase_31 | AC | 6 ms
6,940 KB |
testcase_32 | TLE | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
ソースコード
// ---------- 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 = vec![]; for a in a.iter() { let mut p = vec![]; for a in a.iter() { if dp[a.0] == a.1 { p.push(a.0); } } if p.len() > 0 { ban.push(p); } } ban.sort(); ban.dedup(); for k in 2.. { let mut set = std::collections::BTreeSet::new(); for ban in ban.iter() { if ban.len() >= k { let mut p = vec![0; ban.len()]; for p in p.iter_mut().rev().take(k) { *p = 1; } while { let mut c = vec![]; for (i, p) in p.iter().enumerate() { if *p > 0 { c.push(ban[i]); } } set.insert(c); next_permutation(&mut p) } {} } } 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) } {} } }