結果
問題 | No.408 五輪ピック |
ユーザー | sntea |
提出日時 | 2017-10-28 18:41:51 |
言語 | Rust (1.77.0 + proconio) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,007 bytes |
コンパイル時間 | 18,509 ms |
コンパイル使用メモリ | 387,216 KB |
実行使用メモリ | 394,036 KB |
最終ジャッジ日時 | 2024-11-22 03:53:45 |
合計ジャッジ時間 | 36,025 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
10,624 KB |
testcase_01 | AC | 1 ms
11,008 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 13 ms
5,248 KB |
testcase_06 | AC | 1,459 ms
5,428 KB |
testcase_07 | AC | 103 ms
5,248 KB |
testcase_08 | AC | 9 ms
5,248 KB |
testcase_09 | AC | 9 ms
5,248 KB |
testcase_10 | AC | 1,062 ms
5,248 KB |
testcase_11 | AC | 945 ms
5,248 KB |
testcase_12 | AC | 18 ms
5,280 KB |
testcase_13 | AC | 10 ms
5,248 KB |
testcase_14 | AC | 439 ms
5,248 KB |
testcase_15 | AC | 11 ms
5,248 KB |
testcase_16 | AC | 12 ms
5,248 KB |
testcase_17 | AC | 13 ms
5,248 KB |
testcase_18 | AC | 14 ms
5,248 KB |
testcase_19 | AC | 15 ms
5,504 KB |
testcase_20 | AC | 810 ms
5,248 KB |
testcase_21 | AC | 431 ms
5,248 KB |
testcase_22 | AC | 1,419 ms
5,328 KB |
testcase_23 | AC | 18 ms
6,272 KB |
testcase_24 | TLE | - |
testcase_25 | AC | 14 ms
5,248 KB |
testcase_26 | AC | 1,870 ms
6,400 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 58 ms
5,248 KB |
testcase_29 | AC | 58 ms
5,248 KB |
testcase_30 | AC | 2 ms
5,248 KB |
testcase_31 | MLE | - |
コンパイルメッセージ
warning: unused macro definition: `readlvec` --> src/main.rs:29:14 | 29 | macro_rules! readlvec { | ^^^^^^^^ | = note: `#[warn(unused_macros)]` on by default warning: unused macro definition: `mvec` --> src/main.rs:39:14 | 39 | macro_rules! mvec { | ^^^^ warning: unused macro definition: `debug` --> src/main.rs:48:14 | 48 | macro_rules! debug { | ^^^^^ warning: unused import: `std::collections::HashSet` --> src/main.rs:166:5 | 166 | use std::collections::HashSet; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: function `printiter` is never used --> src/main.rs:54:4 | 54 | fn printiter<'a, T>(v: &'a T) | ^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: method `size` is never used --> src/main.rs:122:8 | 114 | impl Graph { | ---------- method in this implementation ... 122 | fn size(&self) -> usize{ | ^^^^
ソースコード
// use std::ops::{Index, IndexMut}; // use std::cmp::{Ordering, min, max}; // use std::collections::{BinaryHeap, BTreeMap}; // use std::collections::btree_map::Entry::{Occupied, Vacant}; // use std::clone::Clone; fn getline() -> String{ let mut res = String::new(); std::io::stdin().read_line(&mut res).ok(); res } macro_rules! readl { ($t: ty) => { { let s = getline(); s.trim().parse::<$t>().unwrap() } }; ($( $t: ty),+ ) => { { let s = getline(); let mut iter = s.trim().split(' '); ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) } }; } macro_rules! readlvec { ($t: ty) => { { let s = getline(); let iter = s.trim().split(' '); iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>() } } } macro_rules! mvec { ($v: expr, $s: expr) => { vec![$v; $s] }; ($v: expr, $s: expr, $($t: expr),*) => { vec![mvec!($v, $($t),*); $s] }; } macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } } fn printiter<'a, T>(v: &'a T) where &'a T: std::iter::IntoIterator, <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display { for (i,e) in v.into_iter().enumerate() { if i != 0 { print!(" "); } print!("{}", e); } println!(""); } type Cost = i64; #[derive(Clone)] struct Edge { to: usize, cost: Cost, } impl Ord for Edge { fn cmp(&self, other: &Edge) -> std::cmp::Ordering { (-self.cost).cmp(&(-other.cost)) } } impl PartialOrd for Edge { fn partial_cmp(&self, other: &Edge) -> Option<std::cmp::Ordering> { Some(self.cmp(other)) } } impl Eq for Edge {} impl PartialEq for Edge { fn eq(&self, other: &Edge) -> bool { self.cost == other.cost } } #[derive(Clone)] struct Graph { adj: Vec<Vec<Edge>>, } impl std::ops::Index<usize> for Graph { type Output = Vec<Edge>; fn index(&self, i: usize) -> &Vec<Edge> { &self.adj[i] } } impl std::ops::IndexMut<usize> for Graph { fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vec<Edge> { &mut self.adj[i] } } impl Graph { fn new(n: usize) -> Graph{ Graph { adj: vec![vec![]; n], } } fn size(&self) -> usize{ self.adj.capacity() } fn add_edge(&mut self, from: usize, to_: usize, cost_: Cost) { self.adj[from].push(Edge{to: to_, cost: cost_}); } fn add_uedge(&mut self, from: usize, to_: usize, cost_: Cost) { self.add_edge(from, to_, cost_); self.add_edge(to_, from, cost_); } } struct Random { x: i32, y: i32, z: i32, w: i32, t: i32, } impl Random { fn new() -> Random { Random { x: 400, y: 362436069, z: 521288629, w: 886751233, t: 1, } } fn next(&mut self) -> i32 { self.t = self.x^(self.x << 11); self.x = self.y; self.y = self.z; self.z = self.w; self.w = (self.w ^ (self.w>>19)) ^ (self.t ^ (self.t>>8)); self.w&0x7fffffff } } use std::collections::HashSet; // struct Solver { // n: usize, // m: usize, // g: Graph, // } // impl Solver { // fn solve() -> String { // let mut rnd = Random::new(); // for _ in 0..1000 { // let color: Vec<_> = (0..n).map(|_| rnd.next()%5).collect(); // let mut dp = vec![1<<5; n]; // } // } // } impl Graph { fn solve(&self, p: usize, mask: usize, memo: &mut Vec<Vec<Option<bool>>>, color: &Vec<i32>) -> bool { // debug!(mask); if let Some(res) = memo[p][mask] { res } else if mask == (1<<5)-1 { p == 0 } else { let res = self[p].iter().fold(false, |x, y|{ x || if (mask>>color[y.to])&1 == 0 { self.solve(y.to, mask|(1<<color[y.to]), memo, color) } else { false } }); memo[p][mask] = Some(res); res } } } fn main() { let (n, m) = readl!(usize, usize); let g = { let mut g = Graph::new(n); for _ in 0..m { let (a, b) = readl!(usize, usize); g.add_uedge(a-1, b-1, -1); } g }; // let ans = Solver::new(n, m, g); let mut rnd = Random::new(); let mut f = false; 'main: for _ in 0..1000 { let color: Vec<_> = (0..n).map(|_| rnd.next()%5).collect(); let mut dp = vec![vec![None; 1<<5]; n]; let res = g[0].iter().fold(false, |x, y| { x||g.solve(y.to, 1<<color[y.to], &mut dp, &color) }); if res { f = true; break 'main; } } if f { println!("YES"); } else { println!("NO"); } }