結果

問題 No.440 2次元チワワ問題
ユーザー titia
提出日時 2025-01-15 03:28:43
言語 Rust
(1.83.0 + proconio)
結果
MLE  
実行時間 -
コード長 3,682 bytes
コンパイル時間 15,453 ms
コンパイル使用メモリ 400,788 KB
実行使用メモリ 813,292 KB
最終ジャッジ日時 2025-01-15 03:29:50
合計ジャッジ時間 26,775 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 MLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

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![0i64; h * w * w];
fn calc(h: usize, l: usize, w: usize, map: &Vec<Vec<char>>, score: &mut Vec<i64>) {
let mut c = 0i64;
let mut cw = 0i64;
let mut now = 0i64;
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<i64>) {
let mut c = 0i64;
let mut cw = 0i64;
let mut now = 0i64;
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];
}
}
}
{
let mut score2 = vec![0i64; w * h * h];
fn calc3(w: usize, l: usize, h: usize, map: &Vec<Vec<char>>, score2: &mut Vec<i64>) {
let mut c = 0i64;
let mut cw = 0i64;
let mut now = 0i64;
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<i64>) {
let mut c = 0i64;
let mut cw = 0i64;
let mut now = 0i64;
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];
}
}
}
for res in results {
println!("{}", res);
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0