結果

問題 No.703 ゴミ拾い Easy
ユーザー ノロケ・ウイルス
提出日時 2018-06-16 00:28:51
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,216 bytes
コンパイル時間 12,067 ms
コンパイル使用メモリ 404,980 KB
実行使用メモリ 15,648 KB
最終ジャッジ日時 2024-06-30 15:44:38
合計ジャッジ時間 15,069 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 2 WA * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Read, stdin};
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tok = buf.split_whitespace();
    let mut get = || tok.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut hito = vec![];
    for _ in 0..n {
        hito.push(get!());
    }
    let mut gomi_x = vec![];
    for _ in 0..n {
        gomi_x.push(get!());
    }
    let mut gomi_y = vec![];
    for _ in 0..n {
        gomi_y.push(get!());
    }
    let mut h = 0;
    let mut ans = 0;
    for i in 0..n {
        let x = gomi_x[i];
        let y = gomi_y[i];
        while h < i && h < n-1 && hito[h] < x {
            h += 1;
        }
        if h == 0 {
            if n == 1 || h+1>i {
                let dx = hito[h]-x;
                ans += dx*dx+y*y;
            } else {
                let dx = min((hito[h]-x).abs(),(hito[h+1]-x).abs());
                ans += dx*dx+y*y;
            }
        } else {
            let dx = min((hito[h]-x).abs(),(hito[h-1]-x).abs());
            ans += dx*dx+y*y;
        }
    }
    println!("{}", ans);
}
0