QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#427182#8774. Manhattan Walkucup-team635#AC ✓14ms9996kbRust2.7kb2024-06-01 10:49:162024-06-01 10:49:16

Judging History

你现在查看的是最新测评结果

  • [2024-06-01 10:49:16]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:9996kb
  • [2024-06-01 10:49:16]
  • 提交

answer

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

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

// 積分がいるな
//
// 右を示すところに飛び込んだ時
// inf_{0}^{p} L.min(x+D) dx
//

fn main() {
    input! {
        h: usize,
        w: usize,
        p: f64,
    }
    let eval = |base: f64, test: f64| -> f64 {
        let diff = base - test;
        if diff <= 0.0 {
            return base;
        }
        ((p - diff) * base + test * diff + diff * diff * 0.5) / p
    };
    let mut dp = vec![vec![0f64; w]; h];
    for i in (0..h).rev() {
        for j in (0..w).rev() {
            if (i, j) == (h - 1, w - 1) {
                continue;
            }
            let mut val = std::f64::MAX;
            if j + 1 == w {
                val = p * 0.25 + dp[i + 1][j];
            } else if i + 1 == h {
                val = p * 0.25 + dp[i][j + 1];
            } else {
                let r = eval(dp[i][j + 1], dp[i + 1][j]);
                let d = eval(dp[i + 1][j], dp[i][j + 1]);
                val = (r + d) * 0.5;
            }
            dp[i][j] = val;
        }
    }
    println!("{}", dp[0][0]);
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
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_export]
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_export]
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 ----------

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 2224kb

input:

2 3 8

output:

2.875

result:

ok found '2.8750000', expected '2.8750000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 2176kb

input:

5 5 5

output:

2.4322338688738814

result:

ok found '2.4322339', expected '2.4322339', error '0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 2116kb

input:

1 1 1

output:

0

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #4:

score: 0
Accepted
time: 14ms
memory: 9996kb

input:

1000 1000 1000000000

output:

1782317138.808375

result:

ok found '1782317138.8083749', expected '1782317138.8083761', error '0.0000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 2160kb

input:

1 4 5

output:

3.75

result:

ok found '3.7500000', expected '3.7500000', error '0.0000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 2164kb

input:

4 1 5

output:

3.75

result:

ok found '3.7500000', expected '3.7500000', error '0.0000000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 2108kb

input:

1 1 1000000000

output:

0

result:

ok found '0.0000000', expected '0.0000000', error '-0.0000000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 2144kb

input:

1 2 1000000000

output:

250000000

result:

ok found '250000000.0000000', expected '250000000.0000000', error '0.0000000'

Test #9:

score: 0
Accepted
time: 0ms
memory: 2176kb

input:

2 1 1000000000

output:

250000000

result:

ok found '250000000.0000000', expected '250000000.0000000', error '0.0000000'

Test #10:

score: 0
Accepted
time: 0ms
memory: 2148kb

input:

1 2 1

output:

0.25

result:

ok found '0.2500000', expected '0.2500000', error '0.0000000'

Test #11:

score: 0
Accepted
time: 0ms
memory: 2112kb

input:

2 1 1

output:

0.25

result:

ok found '0.2500000', expected '0.2500000', error '0.0000000'

Test #12:

score: 0
Accepted
time: 0ms
memory: 2164kb

input:

1 10 3

output:

6.75

result:

ok found '6.7500000', expected '6.7500000', error '0.0000000'

Test #13:

score: 0
Accepted
time: 0ms
memory: 2140kb

input:

10 1 3

output:

6.75

result:

ok found '6.7500000', expected '6.7500000', error '0.0000000'

Test #14:

score: 0
Accepted
time: 13ms
memory: 9684kb

input:

997 993 998244353

output:

1779941051.3461628

result:

ok found '1779941051.3461628', expected '1779941051.3461628', error '0.0000000'

Test #15:

score: 0
Accepted
time: 2ms
memory: 4392kb

input:

988 313 886183312

output:

78753022570.48328

result:

ok found '78753022570.4832764', expected '78753022570.4833527', error '0.0000000'

Test #16:

score: 0
Accepted
time: 3ms
memory: 3440kb

input:

583 286 322190846

output:

8636356976.843708

result:

ok found '8636356976.8437080', expected '8636356976.8437138', error '0.0000000'

Test #17:

score: 0
Accepted
time: 3ms
memory: 5552kb

input:

892 468 494964816

output:

17125998682.729227

result:

ok found '17125998682.7292271', expected '17125998682.7292328', error '0.0000000'

Test #18:

score: 0
Accepted
time: 0ms
memory: 2268kb

input:

26 882 386682745

output:

78231677700.75046

result:

ok found '78231677700.7504578', expected '78231677700.7504883', error '0.0000000'

Test #19:

score: 0
Accepted
time: 10ms
memory: 8236kb

input:

867 926 422131798

output:

945100500.3991067

result:

ok found '945100500.3991067', expected '945100500.3991071', error '0.0000000'

Test #20:

score: 0
Accepted
time: 0ms
memory: 2148kb

input:

37 68 19

output:

62.284459880159076

result:

ok found '62.2844599', expected '62.2844599', error '0.0000000'

Test #21:

score: 0
Accepted
time: 0ms
memory: 2148kb

input:

23 90 80

output:

860.0506987357912

result:

ok found '860.0506987', expected '860.0506987', error '0.0000000'

Test #22:

score: 0
Accepted
time: 0ms
memory: 2128kb

input:

43 55 85

output:

118.38926796756418

result:

ok found '118.3892680', expected '118.3892680', error '0.0000000'

Test #23:

score: 0
Accepted
time: 0ms
memory: 2280kb

input:

93 66 43

output:

97.90484085875109

result:

ok found '97.9048409', expected '97.9048409', error '0.0000000'

Test #24:

score: 0
Accepted
time: 0ms
memory: 2172kb

input:

78 93 30

output:

44.8454523264506

result:

ok found '44.8454523', expected '44.8454523', error '0.0000000'

Test #25:

score: 0
Accepted
time: 0ms
memory: 2104kb

input:

9 5 481032867

output:

400507342.3667383

result:

ok found '400507342.3667383', expected '400507342.3667384', error '0.0000000'

Test #26:

score: 0
Accepted
time: 1ms
memory: 2248kb

input:

366 73 3

output:

149.48646423309594

result:

ok found '149.4864642', expected '149.4864642', error '0.0000000'

Test #27:

score: 0
Accepted
time: 0ms
memory: 2148kb

input:

6 4 5

output:

2.894645169728758

result:

ok found '2.8946452', expected '2.8946452', error '0.0000000'

Test #28:

score: 0
Accepted
time: 0ms
memory: 2112kb

input:

8 10 5

output:

3.3973608524749084

result:

ok found '3.3973609', expected '3.3973609', error '0.0000000'

Test #29:

score: 0
Accepted
time: 0ms
memory: 2276kb

input:

10 1 7

output:

15.75

result:

ok found '15.7500000', expected '15.7500000', error '0.0000000'

Test #30:

score: 0
Accepted
time: 0ms
memory: 2128kb

input:

10 7 10

output:

7.371646607394142

result:

ok found '7.3716466', expected '7.3716466', error '0.0000000'

Test #31:

score: 0
Accepted
time: 0ms
memory: 2136kb

input:

2 8 1

output:

1.3271069194657823

result:

ok found '1.3271069', expected '1.3271069', error '0.0000000'