Submission #60749184


Source Code Expand

use std::{cmp::Reverse, collections::BinaryHeap};

#[allow(unused_imports)]
use proconio::{input, marker::Usize1};

fn main() {
    input!{
        h: usize,
        w: usize,
        x: u128,
        p: Usize1,
        q: Usize1,
        v: [[u128; w]; h],
    }

    let mut strng = v[p][q];

    let mut seen = vec![vec![false; w]; h];
    seen[p][q] = true;
    let mut pq = BinaryHeap::new();
    for r in 0..4 {
        let ni = p.wrapping_add(DI[r]);
        let nj = q.wrapping_add(DJ[r]);
        if ni < h && nj < w {
            seen[ni][nj] = true;
            pq.push((Reverse(v[ni][nj]), ni, nj));
        }
    }

    while let Some((Reverse(c), i, j)) = pq.pop() {
        if strng <= c * x {
            continue;
        }
        strng += c;
        for r in 0..4 {
            let ni = i.wrapping_add(DI[r]);
            let nj = j.wrapping_add(DJ[r]);
            if ni < h && nj < w && !seen[ni][nj] {
                seen[ni][nj] = true;
                pq.push((Reverse(v[ni][nj]), ni, nj));
            }
        }
    }

    println!("{}", strng);
}

pub static INF: u64 = 1e18 as u64;
pub static DI: &[usize] = &[0, !0, 0, 1, !0, 1, !0, 1];
pub static DJ: &[usize] = &[!0, 0, 1, 0, !0, !0, 1, 1];
pub static DC: &[char] = &['L', 'U', 'R', 'D'];
pub trait Debuggable {
    fn debug_string(&self) -> String;
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for Vec<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        use std::iter::repeat;
        if let Some(max_size) = self.iter()
            .map(|x| format!("{:?}", x).len())
            .max() {
                let mut idx = String::from("idx |");   
                let mut val = String::from("val |");   
                for (i, xi) in self.iter().enumerate() {
                    idx.push_str(
                        &format!(" {:>w$} |", i, w=max_size)
                    );
                    val.push_str(
                        &format!(" {:>w$} |", xi, w=max_size)
                    );
                }

                format!("{}\n{}\n{}\n", idx, repeat('-').take(idx.len()).join(""), val)
            } else {
                format!("idx | \nval |\n")
            }
    }
}

impl<T: std::fmt::Debug + std::fmt::Display> Debuggable for std::collections::BTreeSet<T> {
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!("{{ {} }}", self.iter().join(", "))
    }
}

impl<T, U> Debuggable for std::collections::BTreeMap<T, U> 
where T: std::fmt::Debug + std::fmt::Display, U: std::fmt::Debug + std::fmt::Display
{
    fn debug_string(&self) -> String {
        use itertools::Itertools;
        format!(
            "{{\n{}\n }}", self.iter()
                .map(|(k, v)| format!("{k} -> {v}, "))
                .join("\n")
        )
    }
}

// lg! マクロの定義
#[macro_export]
macro_rules! lg {
    ($val:expr) => {
        #[cfg(feature = "local")]
        {
            {
                use Debuggable;
                let val = &$val;
                eprintln!(
                    "[{}:{}] {} = \n{}",
                    file!(),
                    line!(),
                    stringify!($val),
                    val.debug_string()
                );
                val
            }
        }
    }
}
    

Submission Info

Submission Time
Task E - Takahashi is Slime 2
User ardRiriy
Language Rust (rustc 1.70.0)
Score 450
Code Size 3307 Byte
Status AC
Exec Time 49 ms
Memory 13312 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 65
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 2104 KiB
00_sample_01.txt AC 0 ms 1912 KiB
00_sample_02.txt AC 0 ms 1956 KiB
01_random_03.txt AC 47 ms 11196 KiB
01_random_04.txt AC 2 ms 2248 KiB
01_random_05.txt AC 47 ms 11784 KiB
01_random_06.txt AC 10 ms 4440 KiB
01_random_07.txt AC 48 ms 11836 KiB
01_random_08.txt AC 2 ms 2384 KiB
01_random_09.txt AC 47 ms 11948 KiB
01_random_10.txt AC 8 ms 3656 KiB
01_random_11.txt AC 11 ms 9320 KiB
01_random_12.txt AC 0 ms 2028 KiB
01_random_13.txt AC 11 ms 9396 KiB
01_random_14.txt AC 4 ms 3048 KiB
01_random_15.txt AC 47 ms 11436 KiB
01_random_16.txt AC 1 ms 2100 KiB
01_random_17.txt AC 47 ms 11964 KiB
01_random_18.txt AC 2 ms 2472 KiB
01_random_19.txt AC 45 ms 10928 KiB
01_random_20.txt AC 4 ms 4164 KiB
01_random_21.txt AC 48 ms 11764 KiB
01_random_22.txt AC 2 ms 2880 KiB
01_random_23.txt AC 11 ms 9196 KiB
01_random_24.txt AC 3 ms 3408 KiB
01_random_25.txt AC 11 ms 9320 KiB
01_random_26.txt AC 1 ms 2096 KiB
01_random_27.txt AC 9 ms 8140 KiB
01_random_28.txt AC 3 ms 3368 KiB
01_random_29.txt AC 12 ms 9236 KiB
01_random_30.txt AC 4 ms 4372 KiB
01_random_31.txt AC 11 ms 9164 KiB
01_random_32.txt AC 3 ms 3904 KiB
01_random_33.txt AC 11 ms 9288 KiB
01_random_34.txt AC 6 ms 5920 KiB
01_random_35.txt AC 10 ms 8564 KiB
01_random_36.txt AC 1 ms 2628 KiB
01_random_37.txt AC 9 ms 8012 KiB
01_random_38.txt AC 3 ms 3808 KiB
01_random_39.txt AC 11 ms 9140 KiB
01_random_40.txt AC 2 ms 2744 KiB
01_random_41.txt AC 11 ms 9124 KiB
01_random_42.txt AC 3 ms 4008 KiB
01_random_43.txt AC 0 ms 1952 KiB
01_random_44.txt AC 0 ms 1848 KiB
01_random_45.txt AC 0 ms 1920 KiB
01_random_46.txt AC 1 ms 1932 KiB
01_random_47.txt AC 0 ms 2012 KiB
01_random_48.txt AC 1 ms 1888 KiB
01_random_49.txt AC 1 ms 2096 KiB
01_random_50.txt AC 0 ms 2056 KiB
01_random_51.txt AC 0 ms 2116 KiB
01_random_52.txt AC 0 ms 1876 KiB
01_random_53.txt AC 1 ms 2052 KiB
01_random_54.txt AC 0 ms 1976 KiB
01_random_55.txt AC 1 ms 1984 KiB
01_random_56.txt AC 1 ms 2004 KiB
01_random_57.txt AC 0 ms 1968 KiB
01_random_58.txt AC 47 ms 13156 KiB
01_random_59.txt AC 47 ms 13312 KiB
01_random_60.txt AC 49 ms 13172 KiB
01_random_61.txt AC 0 ms 1888 KiB
01_random_62.txt AC 0 ms 1800 KiB
01_random_63.txt AC 0 ms 2036 KiB
01_random_64.txt AC 0 ms 2012 KiB