結果

問題 No.60 魔法少女
ユーザー ixTL255
提出日時 2023-01-10 23:46:13
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 1,746 bytes
コンパイル時間 28,637 ms
コンパイル使用メモリ 382,136 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-12-21 12:40:49
合計ジャッジ時間 18,141 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: constant `m` should have an upper case name
 --> src/main.rs:4:11
  |
4 |     const m: usize = 1002;
  |           ^ help: convert the identifier to upper case: `M`
  |
  = note: `#[warn(non_upper_case_globals)]` on by default

warning: constant `offset` should have an upper case name
 --> src/main.rs:5:11
  |
5 |     const offset: isize = 500;
  |           ^^^^^^ help: convert the identifier to upper case: `OFFSET`

ソースコード

diff #

use std::io::*;

fn main() {
    const m: usize = 1002;
    const offset: isize = 500;
    let mut stg = vec![vec![0; m]; m];

    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    
    let mut mons = Vec::<(isize, isize, isize)>::new();
    for _ in 0..n {
        mons.push((
            itr.next().unwrap().parse().unwrap(),
            itr.next().unwrap().parse().unwrap(),
            itr.next().unwrap().parse().unwrap()
            ));
    } 

    let mut att = Vec::<(isize, isize, usize, usize, isize)>::new();
    for _ in 0..k {
        att.push((
            itr.next().unwrap().parse().unwrap(),
            itr.next().unwrap().parse().unwrap(),
            itr.next().unwrap().parse().unwrap(),
            itr.next().unwrap().parse().unwrap(),
            itr.next().unwrap().parse().unwrap(),
            ));
    }

    for t in att {
        let x = (t.0 + offset) as usize;
        let y = (t.1 + offset) as usize;
        let xw = std::cmp::min(x + t.2 + 1, m - 1);
        let yh = std::cmp::min(y + t.3 + 1, m - 1);
        let d = t.4;
        stg[x][y] += d;
        stg[xw][y] -= d;
        stg[x][yh] -= d;
        stg[xw][yh] += d;
    }

    for i in 0..m {
        for j in 1..m { stg[i][j] += stg[i][j - 1]; }
    }

    for i in 1..m {
        for j in 0..m { stg[i][j] += stg[i - 1][j]; }
    }

    let mut ans = 0;
    for t in mons {
        let x = (t.0 + offset) as usize;
        let y = (t.1 + offset) as usize;
        let h = t.2;
        ans += std::cmp::max(h - stg[x][y], 0);
    }

    println!("{}", ans);

}
0