結果

問題 No.489 株に挑戦
ユーザー tanzakutanzaku
提出日時 2017-02-24 20:31:30
言語 Rust
(1.77.0)
結果
AC  
実行時間 22 ms / 1,000 ms
コード長 2,543 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 152,712 KB
実行使用メモリ 4,420 KB
最終ジャッジ日時 2023-09-27 04:54:23
合計ジャッジ時間 2,307 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
4,376 KB
testcase_01 AC 11 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 17 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 19 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 12 ms
4,376 KB
testcase_24 AC 21 ms
4,384 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 20 ms
4,380 KB
testcase_27 AC 19 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 22 ms
4,384 KB
testcase_31 AC 21 ms
4,420 KB
testcase_32 AC 12 ms
4,376 KB
testcase_33 AC 21 ms
4,376 KB
testcase_34 AC 18 ms
4,380 KB
testcase_35 AC 7 ms
4,380 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(dead_code)]
fn get_line() -> Vec<String> {
    let stdin = std::io::stdin();
    let mut s = String::new();
    loop {
        stdin.read_line(&mut s).ok();
        let s = s.trim();
        if s.len() != 0 {
            return s.split_whitespace().map(|s| s.into()).collect();
        }
    }
}

#[allow(dead_code)]
fn read_array<T>() -> Vec<T> where
    T: std::str::FromStr + std::marker::Copy,
    <T as std::str::FromStr>::Err: std::fmt::Debug
{
    get_line().iter().map(|s| s.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read2<T, U>() -> (T, U) where
    T: std::str::FromStr + std::marker::Copy,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
    U: std::str::FromStr + std::marker::Copy,
    <U as std::str::FromStr>::Err: std::fmt::Debug
{
    let ary = get_line();
    (ary[0].parse().unwrap(), ary[1].parse().unwrap())
}

#[allow(dead_code)]
fn read3<T, U, W>() -> (T, U, W) where
    T: std::str::FromStr + std::marker::Copy,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
    U: std::str::FromStr + std::marker::Copy,
    <U as std::str::FromStr>::Err: std::fmt::Debug,
    W: std::str::FromStr + std::marker::Copy,
    <W as std::str::FromStr>::Err: std::fmt::Debug
{
    let ary = get_line();
    (ary[0].parse().unwrap(), ary[1].parse().unwrap(), ary[2].parse().unwrap())
}

#[allow(dead_code)]
fn read1<T>() -> T where
    T: std::str::FromStr + std::marker::Copy,
    <T as std::str::FromStr>::Err: std::fmt::Debug
{
    read_array()[0]
}

fn main() {
    let (n, d, k): (usize, i64, i64) = read3();
    let mut x = vec![0; n];
    for i in 0..n {
        x[i] = read1();
    }
    let mut l = 0;
    let mut r = 0;
    let mut ans = 0i64;

    let mut idx = 0;
    let mut max_value = Vec::new();
    for i in (0..n).rev() {
        max_value.push((x[i], -(i as i64)));
        while max_value.len() > 1 {
            let m = max_value.len();
            if max_value[m - 1] < max_value[m - 2] {
                break;
            }
            max_value[m - 2] = max_value[m - 1];
            max_value.pop();
        }
        idx = std::cmp::min(idx, max_value.len() - 1);
        while -max_value[idx].1 - (i as i64) > d {
            idx += 1
        }
        let (val, day) = max_value[idx];
        let profit = val - x[i];
        // println!("{} {} {} {} {}", i, idx, val, day, profit);
        if ans <= profit {
            ans = profit;
            l = i;
            r = -day;
        }
    }
    println!("{}", ans * k);
    if ans != 0 {
        println!("{} {}", l, r);
    }
}
0