結果

問題 No.1599 Hikyaku
ユーザー akakimidoriakakimidori
提出日時 2021-07-09 23:03:37
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 5,006 bytes
コンパイル時間 14,611 ms
コンパイル使用メモリ 378,932 KB
実行使用メモリ 46,152 KB
最終ジャッジ日時 2024-07-01 18:10:37
合計ジャッジ時間 31,757 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
41,728 KB
testcase_01 AC 87 ms
44,260 KB
testcase_02 AC 176 ms
44,128 KB
testcase_03 AC 30 ms
41,600 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 126 ms
41,932 KB
testcase_10 WA -
testcase_11 AC 114 ms
41,600 KB
testcase_12 WA -
testcase_13 AC 206 ms
43,264 KB
testcase_14 AC 82 ms
41,600 KB
testcase_15 AC 140 ms
41,600 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 633 ms
44,032 KB
testcase_26 WA -
testcase_27 AC 528 ms
42,880 KB
testcase_28 WA -
testcase_29 AC 401 ms
42,624 KB
testcase_30 WA -
testcase_31 AC 161 ms
41,600 KB
testcase_32 AC 97 ms
41,600 KB
testcase_33 AC 99 ms
41,600 KB
testcase_34 AC 381 ms
41,856 KB
testcase_35 AC 566 ms
42,240 KB
testcase_36 AC 562 ms
42,496 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 30 ms
41,600 KB
testcase_42 AC 136 ms
41,728 KB
testcase_43 AC 70 ms
41,600 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 30 ms
41,728 KB
testcase_50 AC 30 ms
41,728 KB
testcase_51 AC 31 ms
41,600 KB
testcase_52 AC 206 ms
42,496 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
  --> src/main.rs:72:5
   |
72 | use std::io::Write;
   |     ^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: type alias `Map` is never used
  --> src/main.rs:76:6
   |
76 | type Map<K, V> = BTreeMap<K, V>;
   |      ^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: type alias `Set` is never used
  --> src/main.rs:77:6
   |
77 | type Set<T> = BTreeSet<T>;
   |      ^^^

ソースコード

diff #

// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::io::Write;
use std::collections::*;
use std::cmp::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn diff(x: usize, y: usize) -> usize {
    x.max(y) - x.min(y)
}

#[derive(Clone, Copy)]
pub struct F(f64);

impl Ord for F {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.partial_cmp(other).unwrap()
    }
}

impl PartialOrd for F {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        self.0.partial_cmp(&other.0)
    }
}

impl PartialEq for F {
    fn eq(&self, other: &Self) -> bool {
        self.0 == other.0
    }
}

impl Eq for F {}

fn run() {
    input! {
        dst: (usize1, usize1),
        n: usize,
        p: [(usize1, usize1, usize); n],
    }
    let m = 600;
    let w = 1000f64;
    let mut ans = (diff(dst.0, p[0].0) + diff(dst.1, p[0].1)) as f64 * w;
    let inf = ans;
    let src = p[0];
    let mut point = vec![vec![]; 7];
    for (x, y, v) in p {
        point[v - 1].push((x, y));
    }
    let mut memo = vec![];
    for (i, p) in point.iter().enumerate() {
        let mut dp = vec![vec![inf; m]; m];
        let add = w / (i + 1) as f64;
        let mut q = Deque::new();
        for &(x, y) in p.iter() {
            dp[x][y] = 0f64;
            q.push_back((x, y));
        }
        while let Some((x, y)) = q.pop_front() {
            let d = dp[x][y] + add;
            for &(x, y) in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)].iter() {
                if x < m && y < m && dp[x][y].chmin(d) {
                    q.push_back((x, y));
                }
            }
        }
        memo.push(dp);
    }
    let mut dp = vec![vec![vec![inf; m]; m]; 7];
    dp[src.2 - 1][src.0][src.1] = 0f64;
    let mut h = BinaryHeap::new();
    h.push((Reverse(F(0f64)), src.2 - 1, src.0, src.1));
    while let Some((Reverse(F(d)), v, x, y)) = h.pop() {
        if d > dp[v][x][y] {
            continue;
        }
        let val = d + w / (v + 1) as f64;
        let src = (x, y);
        for &(x, y) in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)].iter() {
            if x < m && y < m && dp[v][x][y].chmin(val) {
                h.push((Reverse(F(val)), v, x, y));
                for i in (v + 1)..7 {
                    if memo[i][x][y] > d {
                        let time = memo[i][x][y] - d;
                        let rem = 0f64.max(w - (v + 1) as f64 * time);
                        let meet = rem / (i + 1 + v + 1) as f64;
                        if dp[i][x][y].chmin(memo[i][x][y] + meet + meet) {
                            h.push((Reverse(F(dp[i][x][y])), i, x, y));
                        }
                        let w = w - meet * (i + 1) as f64;
                        if dp[i][src.0][src.1].chmin(memo[i][x][y] + meet + w / (i + 1) as f64) {
                            h.push((Reverse(F(dp[i][src.0][src.1])), i, x, y));
                        }
                    }
                }
            }
        }
    }
    for dp in dp {
        ans.chmin(dp[dst.0][dst.1]);
    }
    println!("{:.8}", ans);
}

fn main() {
    run();
}
0