結果
問題 | No.1711 Divide LCM |
ユーザー | akakimidori |
提出日時 | 2021-10-15 22:48:34 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 2,045 ms / 4,000 ms |
コード長 | 3,952 bytes |
コンパイル時間 | 15,909 ms |
コンパイル使用メモリ | 378,852 KB |
実行使用メモリ | 66,348 KB |
最終ジャッジ日時 | 2024-11-08 09:20:06 |
合計ジャッジ時間 | 29,326 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 3 ms
5,248 KB |
testcase_03 | AC | 3 ms
5,248 KB |
testcase_04 | AC | 9 ms
5,248 KB |
testcase_05 | AC | 45 ms
5,248 KB |
testcase_06 | AC | 14 ms
5,248 KB |
testcase_07 | AC | 34 ms
5,248 KB |
testcase_08 | AC | 10 ms
5,248 KB |
testcase_09 | AC | 65 ms
5,248 KB |
testcase_10 | AC | 20 ms
5,248 KB |
testcase_11 | AC | 129 ms
5,248 KB |
testcase_12 | AC | 20 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 5 ms
5,248 KB |
testcase_15 | AC | 9 ms
5,248 KB |
testcase_16 | AC | 3 ms
5,248 KB |
testcase_17 | AC | 5 ms
5,248 KB |
testcase_18 | AC | 58 ms
19,508 KB |
testcase_19 | AC | 59 ms
19,508 KB |
testcase_20 | AC | 59 ms
19,504 KB |
testcase_21 | AC | 91 ms
18,156 KB |
testcase_22 | AC | 2,045 ms
65,664 KB |
testcase_23 | AC | 1,405 ms
66,348 KB |
testcase_24 | AC | 115 ms
11,416 KB |
testcase_25 | AC | 108 ms
11,548 KB |
testcase_26 | AC | 101 ms
11,544 KB |
testcase_27 | AC | 102 ms
11,812 KB |
testcase_28 | AC | 105 ms
11,632 KB |
testcase_29 | AC | 5 ms
5,248 KB |
testcase_30 | AC | 127 ms
14,992 KB |
testcase_31 | AC | 5 ms
5,248 KB |
testcase_32 | AC | 153 ms
17,392 KB |
testcase_33 | AC | 81 ms
17,520 KB |
testcase_34 | AC | 10 ms
5,248 KB |
testcase_35 | AC | 181 ms
14,960 KB |
testcase_36 | AC | 211 ms
14,960 KB |
testcase_37 | AC | 210 ms
15,104 KB |
testcase_38 | AC | 95 ms
23,880 KB |
testcase_39 | AC | 94 ms
17,332 KB |
testcase_40 | AC | 3 ms
5,248 KB |
testcase_41 | AC | 3 ms
5,248 KB |
testcase_42 | AC | 2 ms
5,248 KB |
testcase_43 | AC | 3 ms
5,248 KB |
testcase_44 | AC | 3 ms
5,248 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::HashSet::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); } } for i in 1..(1 << p.len()) { let mut x = vec![]; for (j, p) in p.iter().enumerate() { if i >> j & 1 == 1 { x.push(*p as u32); } } ban.insert(x); } } 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] as u32); } } if !ban.contains(&x) { let mut ans = vec![vec![]; k]; for a in a { for (ans, &x) in ans.iter_mut().zip(&x) { let x = x as usize; 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) } {} } }