結果
| 問題 |
No.440 2次元チワワ問題
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-01-15 03:33:12 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 952 ms / 5,000 ms |
| コード長 | 3,696 bytes |
| コンパイル時間 | 17,795 ms |
| コンパイル使用メモリ | 401,840 KB |
| 実行使用メモリ | 491,788 KB |
| 最終ジャッジ日時 | 2025-01-15 03:33:42 |
| 合計ジャッジ時間 | 28,680 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
use std::io;
fn main() {
let stdin = io::stdin();
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
let dims: Vec<usize> = input.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
let (h, w) = (dims[0], dims[1]);
let mut map = Vec::new();
for _ in 0..h {
input.clear();
stdin.read_line(&mut input).unwrap();
map.push(input.trim().chars().collect::<Vec<char>>());
}
input.clear();
stdin.read_line(&mut input).unwrap();
let q: usize = input.trim().parse().unwrap();
let mut queries = Vec::new();
for _ in 0..q {
input.clear();
stdin.read_line(&mut input).unwrap();
let query: Vec<usize> = input.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
queries.push((query[0] - 1, query[1] - 1, query[2] - 1, query[3] - 1));
}
let mut results = vec![0i64; q];
{
let mut score = vec![0i32; h * w * w];
fn calc(h: usize, l: usize, w: usize, map: &Vec<Vec<char>>, score: &mut Vec<i32>) {
let mut c = 0i32;
let mut cw = 0i32;
let mut now = 0i32;
for i in l..w {
if map[h][i] == 'c' {
c += 1;
} else {
now += cw;
cw += c;
}
score[h * w * w + l * w + i] += now;
}
}
fn calc2(h: usize, r: usize, w: usize, map: &Vec<Vec<char>>, score: &mut Vec<i32>) {
let mut c = 0i32;
let mut cw = 0i32;
let mut now = 0i32;
for i in (0..=r).rev() {
if map[h][i] == 'c' {
c += 1;
} else {
now += cw;
cw += c;
}
score[h * w * w + i * w + r] += now;
}
}
for i in 0..h {
for j in 0..w {
calc(i, j, w, &map, &mut score);
calc2(i, j, w, &map, &mut score);
}
}
for (qi, &(a, b, c, d)) in queries.iter().enumerate() {
for i in a..=c {
results[qi] += score[i * w * w + b * w + d] as i64;
}
}
}
{
let mut score2 = vec![0i32; w * h * h];
fn calc3(w: usize, l: usize, h: usize, map: &Vec<Vec<char>>, score2: &mut Vec<i32>) {
let mut c = 0i32;
let mut cw = 0i32;
let mut now = 0i32;
for i in l..h {
if map[i][w] == 'c' {
c += 1;
} else {
now += cw;
cw += c;
}
score2[w * h * h + l * h + i] += now;
}
}
fn calc4(w: usize, r: usize, h: usize, map: &Vec<Vec<char>>, score2: &mut Vec<i32>) {
let mut c = 0i32;
let mut cw = 0i32;
let mut now = 0i32;
for i in (0..=r).rev() {
if map[i][w] == 'c' {
c += 1;
} else {
now += cw;
cw += c;
}
score2[w * h * h + i * h + r] += now;
}
}
for i in 0..w {
for j in 0..h {
calc3(i, j, h, &map, &mut score2);
calc4(i, j, h, &map, &mut score2);
}
}
for (qi, &(a, b, c, d)) in queries.iter().enumerate() {
for i in b..=d {
results[qi] += score2[i * h * h + a * h + c] as i64;
}
}
}
for res in results {
println!("{}", res);
}
}
titia