結果

問題 No.2566 美しい整数列
ユーザー あさくちあさくち
提出日時 2023-12-02 17:00:14
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,715 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 193,976 KB
実行使用メモリ 19,292 KB
最終ジャッジ日時 2023-12-02 17:00:42
合計ジャッジ時間 4,811 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 0 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 58 ms
19,292 KB
testcase_05 AC 60 ms
18,832 KB
testcase_06 WA -
testcase_07 AC 43 ms
11,556 KB
testcase_08 AC 43 ms
11,612 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 51 ms
13,536 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 46 ms
13,468 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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

fn main() {
    let (n, m) = input_tuple::<usize>();
    let a_org = input_vec::<isize>();
    let b = input_vec();
    let c = input_vec::<isize>();

    let mut a = a_org.clone();

    let mut list = vec![0; n];

    for i in 1..n {
        if a[i] - a[i - 1] != b[(i - 1) % m] {
            list[i] = b[(i - 1) % m] + a[i - 1] - a[i];

            a[i] = b[(i - 1) % m] + a[i - 1];
        }
    }

    // println!("{:?}", list);

    let mut counter = HashMap::new();

    for i in 0..n {
        *counter.entry(list[i]).or_insert(0) += 1;
    }

    let (&_, &max_value) = counter.iter().max().unwrap();

    let mut max_index = 0;

    for i in 0..n {
        if list[i] == max_value {
            max_index = i;
            break;
        }
    }

    max_index += 1;

    eprintln!("max {}", max_index);

    // let mut result_1 = 0;

    // let mut a = a_org.clone();

    // for i in 1..n {
    //     if a[i] - a[i - 1] != b[(i - 1) % m] {
    //         a[i] = b[(i - 1) % m] + a[i - 1];

    //         result_1 += c[i];
    //     }
    // }

    // println!("{:?}", a);

    // println!("{}", result_1);

    // let mut result_2 = 0;

    // let mut a = a_org.clone();

    // for i in (0..n - 1).rev() {
    //     if a[i + 1] - a[i] != b[i % m] {
    //         a[i] = a[i + 1] - b[i % m];

    //         result_2 += c[i];
    //     }
    // }

    // // println!("{:?}", a);

    // println!("{}", result_2);

    let mut result_3 = 0;

    let mut a = a_org.clone();

    for i in max_index..n {
        if a[i] - a[i - 1] != b[(i - 1) % m] {
            a[i] = b[(i - 1) % m] + a[i - 1];

            result_3 += c[i];
        }
    }

    for i in (0..max_index - 1).rev() {
        if a[i + 1] - a[i] != b[i % m] {
            a[i] = a[i + 1] - b[i % m];

            result_3 += c[i];
        }
    }

    // println!("{:?}", a);

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

fn input_tuple<T>() -> (T, T)
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = std::io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf = buf.trim_end().to_owned();

    let mut iter = buf.split_whitespace();

    let n = iter.next().unwrap().parse().unwrap();
    let m = iter.next().unwrap().parse().unwrap();

    (n, m)
}

fn input_vec<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = std::io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf = buf.trim_end().to_owned();

    let iter = buf.split_whitespace();

    let line = iter.map(|x| x.parse().unwrap()).collect();

    line
}
0