結果

問題 No.2566 美しい整数列
ユーザー atcoder8
提出日時 2023-12-02 18:03:59
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,452 bytes
コンパイル時間 14,253 ms
コンパイル使用メモリ 377,784 KB
実行使用メモリ 17,296 KB
最終ジャッジ日時 2024-09-26 21:20:28
合計ジャッジ時間 15,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

fn main() {
    let (n, m) = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse::<usize>().unwrap(),
            iter.next().unwrap().parse::<usize>().unwrap(),
        )
    };
    let aa: Vec<_> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse::<i64>().unwrap())
            .collect()
    };
    let bb: Vec<_> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse::<i64>().unwrap())
            .collect()
    };
    let cc: Vec<_> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse::<usize>().unwrap())
            .collect()
    };

    let mut diff = vec![0; n];
    let mut cur = 0;
    for (i, &a) in aa.iter().enumerate() {
        diff[i] = cur - a;
        cur += bb[i % m];
    }

    let mut counter: HashMap<i64, usize> = HashMap::new();
    for (i, &d) in diff.iter().enumerate() {
        *counter.entry(d).or_default() += cc[i];
    }

    let ans = cc.iter().sum::<usize>() - counter.values().max().unwrap();
    println!("{}", ans);
}
0