結果
問題 | No.2956 Substitute with Average |
ユーザー |
|
提出日時 | 2024-11-20 11:46:16 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 192 ms / 3,000 ms |
コード長 | 947 bytes |
コンパイル時間 | 17,675 ms |
コンパイル使用メモリ | 383,672 KB |
実行使用メモリ | 29,408 KB |
最終ジャッジ日時 | 2024-11-20 11:46:38 |
合計ジャッジ時間 | 16,506 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#[allow(unused_imports)] use proconio::{ input, marker::{Bytes, Chars, Usize1}, }; const C: i64 = 100_000 * 30 + 10; fn main() { input! { n: usize, a: [i64; n], } let mut res = n * (n + 1) / 2; for x in 1..=30 { let mut b = vec![0; n + 1]; for i in 0..n { b[i + 1] = b[i] + (a[i] - x); } let mut cnt1 = vec![0; (C * 2) as usize]; let mut cnt2 = vec![0; (C * 2) as usize]; for i in 0..=n { if i > 0 { if a[i - 1] == x { res -= cnt1[(b[i] + C) as usize]; } res -= cnt2[(b[i] + C) as usize]; } if i < n { if a[i] == x { cnt2[(b[i] + C) as usize] += 1; } else { cnt1[(b[i] + C) as usize] += 1; } } } } println!("{}", res + 1); }