結果
問題 | No.382 シャイな人たち (2) |
ユーザー | akakimidori |
提出日時 | 2021-10-02 12:22:40 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1,089 ms / 8,000 ms |
コード長 | 2,671 bytes |
コンパイル時間 | 14,904 ms |
コンパイル使用メモリ | 378,712 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 05:59:28 |
合計ジャッジ時間 | 32,876 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,089 ms
5,248 KB |
testcase_01 | AC | 1,082 ms
5,376 KB |
testcase_02 | AC | 878 ms
5,376 KB |
testcase_03 | AC | 979 ms
5,376 KB |
testcase_04 | AC | 889 ms
5,376 KB |
testcase_05 | AC | 998 ms
5,376 KB |
testcase_06 | AC | 705 ms
5,376 KB |
testcase_07 | AC | 1,032 ms
5,376 KB |
testcase_08 | AC | 764 ms
5,376 KB |
testcase_09 | AC | 845 ms
5,376 KB |
testcase_10 | AC | 838 ms
5,376 KB |
testcase_11 | AC | 713 ms
5,376 KB |
testcase_12 | AC | 912 ms
5,376 KB |
testcase_13 | AC | 902 ms
5,376 KB |
testcase_14 | AC | 1,053 ms
5,376 KB |
testcase_15 | AC | 1,055 ms
5,376 KB |
testcase_16 | AC | 871 ms
5,376 KB |
testcase_17 | AC | 823 ms
5,376 KB |
testcase_18 | AC | 994 ms
5,376 KB |
testcase_19 | AC | 848 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
ソースコード
type BIT = u128; pub struct BitOne(BIT); use std::iter::*; impl Iterator for BitOne { type Item = usize; fn next(&mut self) -> Option<Self::Item> { if self.0 == 0 { None } else { let y = self.0.trailing_zeros() as usize; self.0 ^= 1 << y; Some(y) } } } struct Graph { size: usize, edge: Vec<BIT>, } impl Graph { fn new(size: usize) -> Self { assert!(std::mem::size_of::<BIT>() * 8 >= size); Graph { size: size, edge: (0..size).map(|x| (1 as BIT) << x as BIT).collect(), } } fn add_edge(&mut self, s: usize, t: usize) { assert!(s != t); self.edge[s] |= (1 as BIT) << t as BIT; self.edge[t] |= (1 as BIT) << s as BIT; } fn rec(&self, rem: BIT) -> (u32, BIT) { if rem == 0 { return (0, 0); } let mut max = (0, 0); for v in BitOne(rem) { let c = (self.edge[v] & rem).count_ones(); if c <= 2 { let (x, y) = self.rec(rem & !self.edge[v]); return (x + 1, y | (1 << v)); } max = (c, v).max(max); } let v = max.1; let a = self.rec(rem ^ (1 << v)); let (x, y) = self.rec(rem & !self.edge[v]); a.max((x + 1, y | (1 << v))) } fn solve(&self) -> Vec<usize> { let mask = if self.size == std::mem::size_of::<BIT>() * 8 { !0 } else { ((1 as BIT) << self.size as BIT) - 1 }; let ans = self.rec(mask).1; BitOne(ans).collect::<Vec<_>>() } } struct RNG { s: usize } impl RNG { fn new(seed: usize) -> Self { RNG { s: seed, } } fn next(&mut self) -> usize { self.s = self.s * 12345 % 1000003; self.s } } fn run() { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let mut rng = RNG::new(s.trim().parse().unwrap()); let n: usize = rng.next() % 120 + 2; let mut graph = Graph::new(n); let p = rng.next(); let mut cnt = 0; for i in 1..=n { for j in (i + 1)..=n { let e = rng.next(); if e >= p { cnt += 1; graph.add_edge(i - 1, j - 1); } } } if cnt == 0 { println!("-1"); return; } let ans = graph.solve(); let mut out = String::new(); out.push_str(&format!("{}\n", ans.len() + 1)); for a in ans { out.push_str(&format!("{} ", a + 1)); } out.pop(); println!("{}", out); } fn main() { run(); }