提出 #70452327


ソースコード 拡げる

#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]
#![allow(unused_macros)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

type Vec2<T> = Vec<Vec<T>>;
type Vec3<T> = Vec<Vec<Vec<T>>>;
#[rustfmt::skip]
macro_rules ! max { ( $x : expr ) => ( $x ) ; ( $x : expr , $ ( $xs : expr ) ,+ ) => { {  std :: cmp :: max ( $x , max! ( $ ( $xs ) ,+ ) ) } } ; }
#[rustfmt::skip]
macro_rules ! min { ( $x : expr ) => ( $x ) ; ( $x : expr , $ ( $xs : expr ) ,+ ) => { {  std :: cmp :: min ( $x , min! ( $ ( $xs ) ,+ ) ) } } ; }
#[rustfmt::skip]
macro_rules! chmin {    ($a:expr, $($b:expr),+) => {{        let d = min!($($b),+);        if $a > d {            $a = d;            true        } else {            false        }    }}; }

#[rustfmt::skip]
macro_rules! chmax {    ($a:expr, $($b:expr),+) => {{        let d = max!($($b),+);        if $a < d {            $a = d;            true        } else {            false        }    }};}

#[rustfmt::skip]
macro_rules! chadd {    ($a:expr, $b:expr) => {{        $a = $a + $b;    }};}
#[rustfmt::skip]
macro_rules! chsub {    ($a:expr, $b:expr) => {{        $a = $a - $b;    }};}
#[rustfmt::skip]
macro_rules! chmul {    ($a:expr, $b:expr) => {{        $a = $a * $b;    }};}

#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

macro_rules! multivec {
    ($a:expr;$b:expr) => {
        vec![$a; $b]
    };
    ($a:expr;$b:expr;$($c:expr);+) => {
        multivec![vec![$a;$b];$($c);+]
    };
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Rem, Sub};

fn echoNoReturn() {
    echo!("No");
    std::process::exit(0);
}
fn echoYesReturn() {
    echo!("Yes");
    std::process::exit(0);
}

fn echoNo() {
    echo!("No");
}
fn echoYes() {
    echo!("Yes");
}

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

fn sin(a: f64) -> f64 {
    a.sin()
}
fn cos(a: f64) -> f64 {
    a.cos()
}
trait ToNum {
    fn toNum(&self) -> Vec<usize>;
}
impl ToNum for Vec<char> {
    fn toNum(&self) -> Vec<usize> {
        if self[0].is_ascii_digit() {
            self.iter().map(|x| x.toNumIndex()).toVec()
        } else {
            self.iter().map(|x| x.toAlphabetIndex()).toVec()
        }
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}
trait PrimeNumber:
    Copy
    + Ord
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + Div<Output = Self>
    + Rem<Output = Self>
{
    fn is_odd(self) -> bool;
    fn is_even(self) -> bool;
    fn pow(self, exp: u32) -> Self;
}

macro_rules! impl_prim_int(($($ty:ty),*) => {
    $(
        impl PrimeNumber for $ty {
            fn pow(self, exp: u32) -> Self {
                self.pow(exp)
            }
            fn is_odd(self)->bool{
                self & 1==1
            }

            fn is_even(self)->bool{
                self & 1==0
            }
        }
    )*
});

trait SafeRangeContain {
    fn safe_contains(&self, x: i64) -> bool;
}

impl SafeRangeContain for std::ops::Range<usize> {
    fn safe_contains(&self, x: i64) -> bool {
        if x < 0 {
            return false;
        }
        return self.contains(&(x as usize));
    }
}

impl_prim_int!(
    u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize
);
trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

use itertools_num::ItertoolsNum as _;
use superslice::*;

fn main() {
    input! {
       N: usize,
       M:usize,
       edges:[(Usize1,Usize1);M],
       S:Chars,
    }
    let mut s = S.iter().map(|&x| x == 'S').toVec();
    let mut dist = vec![HashMap::new(); N];
    let mut kouho = BinaryHeap::new();
    for i in 0..N {
        if s[i] {
            kouho.push(Reverse((0, i, i)));
            dist[i].entry(i).or_insert(0);
        }
    }
    //(dist ,p,from)

    let mut g = vec![vec![]; N];
    for &(u, v) in &edges {
        g[u].push(v);
        g[v].push(u);
    }
    while !kouho.is_empty() {
        let Reverse((d, p, q)) = kouho.pop().unwrap();
        for &next in &g[p] {
            let mut nd = d + 1;
            let mut flag = false;
            if dist[next].len() == 0 {
                dist[next].entry(q).or_insert(nd);
                flag = true;
            } else if dist[next].len() == 1 {
                if !dist[next].keys().contains(&q) {
                    dist[next].entry(q).or_insert(nd);
                    flag = true;
                }
            } else {
                let mut x = 0;
                for (_, v) in &dist[next] {
                    chmax!(x, *v);
                }
                if x > nd {
                    if dist[next].keys().contains(&q) {
                        if *dist[next].get(&q).unwrap() > nd {
                            *dist[next].get_mut(&q).unwrap() = nd;
                            flag = true;
                        }
                    } else {
                        dist[next].entry(q).or_insert(nd);
                        let mut x = 0;
                        let mut index = 0;
                        for (k, v) in &dist[next] {
                            if chmax!(x, *v) {
                                index = *k;
                            }
                        }
                        dist[next].remove(&index);
                        flag = true;
                    }
                }
            }

            if flag {
                kouho.push(Reverse((nd, next, q)));
            }
        }
    }

    let mut ans = vec![];
    for i in 0..N {
        if s[i] {
            continue;
        }

        let mut ret = 0;
        assert_eq!(dist[i].len(), 2);
        for (_, v) in &dist[i] {
            ret += v;
        }
        ans.push(ret);
    }
    echo!(ans.joinToString("\n"));
}

提出情報

提出日時
問題 E - Hit and Away
ユーザ bqn
言語 Rust (rustc 1.70.0)
得点 450
コード長 7560 Byte
結果 AC
実行時間 276 ms
メモリ 70212 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 2
AC × 54
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 1880 KiB
example_01.txt AC 1 ms 1936 KiB
hand_00.txt AC 182 ms 63788 KiB
hand_01.txt AC 218 ms 60264 KiB
hand_02.txt AC 276 ms 56748 KiB
hand_03.txt AC 188 ms 65332 KiB
hand_04.txt AC 202 ms 70212 KiB
hand_05.txt AC 16 ms 12388 KiB
hand_06.txt AC 16 ms 12476 KiB
hand_07.txt AC 141 ms 63988 KiB
hand_08.txt AC 110 ms 41008 KiB
hand_09.txt AC 15 ms 10696 KiB
hand_10.txt AC 104 ms 63980 KiB
hand_11.txt AC 102 ms 59740 KiB
hand_12.txt AC 100 ms 59608 KiB
hand_13.txt AC 123 ms 55424 KiB
hand_14.txt AC 196 ms 64636 KiB
hand_15.txt AC 199 ms 65588 KiB
random_00.txt AC 248 ms 64320 KiB
random_01.txt AC 236 ms 63684 KiB
random_02.txt AC 232 ms 62936 KiB
random_03.txt AC 250 ms 64700 KiB
random_04.txt AC 242 ms 63532 KiB
random_05.txt AC 240 ms 62896 KiB
random_06.txt AC 149 ms 63384 KiB
random_07.txt AC 159 ms 63232 KiB
random_08.txt AC 159 ms 62560 KiB
random_09.txt AC 179 ms 63388 KiB
random_10.txt AC 178 ms 63104 KiB
random_11.txt AC 185 ms 62312 KiB
random_12.txt AC 148 ms 63492 KiB
random_13.txt AC 150 ms 63016 KiB
random_14.txt AC 161 ms 62468 KiB
random_15.txt AC 187 ms 63768 KiB
random_16.txt AC 171 ms 63268 KiB
random_17.txt AC 180 ms 62876 KiB
random_18.txt AC 10 ms 7020 KiB
random_19.txt AC 11 ms 8328 KiB
random_20.txt AC 13 ms 10324 KiB
random_21.txt AC 13 ms 10320 KiB
random_22.txt AC 12 ms 9212 KiB
random_23.txt AC 9 ms 7288 KiB
random_24.txt AC 36 ms 15808 KiB
random_25.txt AC 34 ms 15312 KiB
random_26.txt AC 35 ms 15336 KiB
random_27.txt AC 32 ms 15176 KiB
random_28.txt AC 41 ms 17220 KiB
random_29.txt AC 34 ms 14844 KiB
random_30.txt AC 263 ms 61092 KiB
random_31.txt AC 153 ms 36788 KiB
random_32.txt AC 190 ms 44616 KiB
random_33.txt AC 273 ms 55140 KiB
random_34.txt AC 172 ms 41044 KiB
random_35.txt AC 173 ms 40332 KiB