結果
問題 | No.1147 土偶Ⅱ |
ユーザー | cympfh |
提出日時 | 2020-08-08 01:24:31 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 6 ms / 500 ms |
コード長 | 4,652 bytes |
コンパイル時間 | 13,069 ms |
コンパイル使用メモリ | 382,980 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-11 10:15:41 |
合計ジャッジ時間 | 13,388 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 4 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 6 ms
6,816 KB |
testcase_12 | AC | 3 ms
6,816 KB |
testcase_13 | AC | 1 ms
6,816 KB |
testcase_14 | AC | 5 ms
6,820 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,816 KB |
testcase_17 | AC | 1 ms
6,820 KB |
testcase_18 | AC | 1 ms
6,816 KB |
testcase_19 | AC | 3 ms
6,816 KB |
testcase_20 | AC | 1 ms
6,816 KB |
testcase_21 | AC | 1 ms
6,820 KB |
testcase_22 | AC | 2 ms
6,820 KB |
ソースコード
#![allow(unused_imports, unused_macros, dead_code)] macro_rules! min { (.. $x:expr) => {{ let mut it = $x.iter(); it.next().map(|z| it.fold(z, |x, y| min!(x, y))) }}; ($x:expr) => ($x); ($x:expr, $($ys:expr),*) => {{ let t = min!($($ys),*); if $x < t { $x } else { t } }} } macro_rules! max { (.. $x:expr) => {{ let mut it = $x.iter(); it.next().map(|z| it.fold(z, |x, y| max!(x, y))) }}; ($x:expr) => ($x); ($x:expr, $($ys:expr),*) => {{ let t = max!($($ys),*); if $x > t { $x } else { t } }} } macro_rules! ewriteln { ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); }; } macro_rules! trace { ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) }; ($($xs:expr),*) => { trace!(($($xs),*)) } } macro_rules! flush { () => { std::io::stdout().flush().unwrap(); }; } macro_rules! put { (.. $x:expr) => {{ let mut it = $x.iter(); if let Some(x) = it.next() { print!("{}", x); } for x in it { print!(" {}", x); } println!(""); }}; ($x:expr) => { println!("{}", $x) }; ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) } } trait Group: std::ops::Add<Output = Self> + std::ops::Sub<Output = Self> + std::ops::Neg<Output = Self> + std::iter::Sum + Clone + Copy { fn zero() -> Self; } impl Group for i32 { fn zero() -> Self { 0 } } impl Group for i64 { fn zero() -> Self { 0 } } impl Group for i128 { fn zero() -> Self { 0 } } impl Group for f32 { fn zero() -> Self { 0.0 } } impl Group for f64 { fn zero() -> Self { 0.0 } } #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)] enum Hyper<X> { NegInf, Real(X), Inf, } use Hyper::{Inf, NegInf, Real}; impl<X> Hyper<X> { fn unwrap(self) -> X { if let Hyper::Real(x) = self { x } else { panic!() } } } impl<X: Group> std::ops::Add for Hyper<X> { type Output = Self; fn add(self, rhs: Hyper<X>) -> Hyper<X> { match (self, rhs) { (Real(x), Real(y)) => Real(x + y), (Inf, _) => Inf, (_, Inf) => Inf, _ => NegInf, } } } impl<X: Group> std::ops::Sub for Hyper<X> { type Output = Self; fn sub(self, rhs: Hyper<X>) -> Hyper<X> { self + (-rhs) } } impl<X: Group> std::ops::Neg for Hyper<X> { type Output = Self; fn neg(self) -> Hyper<X> { match self { Inf => NegInf, NegInf => Inf, Real(x) => Real(-x), } } } fn wall<X: Group + PartialOrd>(d: &mut Vec<Vec<Hyper<X>>>) { let n = d.len(); for k in 0..n { for i in 0..n { for j in 0..n { d[i][j] = min!(d[i][j], d[i][k] + d[k][j]); } } } } fn main() { let mut sc = Scanner::new(); let n: usize = sc.cin(); let m: usize = sc.cin(); let mut d: Vec<Vec<Hyper<i64>>> = vec![vec![Inf; n]; n]; for i in 0..n { d[i][i] = Real(0); } for _ in 0..m { let a = sc.cin::<usize>() - 1; let b = sc.cin::<usize>() - 1; d[a][b] = Real(1); d[b][a] = Real(1); } wall(&mut d); let mut ans = 0; for i in 0..n { for j in 0..i { if d[i][j] == Real(2) { continue; } for k in 0..j { if d[i][k] == Real(2) { continue; } if d[j][k] == Real(2) { continue; } ans += 1; } } } put!(ans); } use std::collections::VecDeque; use std::io::{self, Write}; use std::str::FromStr; struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, } impl Scanner { fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new(), } } fn cin<T: FromStr>(&mut self) -> T { while self.buffer.is_empty() { let mut line = String::new(); let _ = self.stdin.read_line(&mut line); for w in line.split_whitespace() { self.buffer.push_back(String::from(w)); } } self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap() } fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() } fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() } }