結果
| 問題 |
No.1505 Zero-Product Ranges
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-11-03 23:08:04 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 740 bytes |
| コンパイル時間 | 12,213 ms |
| コンパイル使用メモリ | 378,156 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 05:17:35 |
| 合計ジャッジ時間 | 15,032 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
fn main() {
let mut n = String::new();
std::io::stdin().read_line(&mut n).ok();
let n: usize = n.trim().parse().unwrap();
let mut a = String::new();
std::io::stdin().read_line(&mut a).ok();
let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
let calc = |x: usize| x * (x + 1) / 2;
let mut result = calc(n);
let mut avals = vec![];
let mut idx = 0usize;
for i in 1..n {
if a[idx] != a[i] {
if a[idx] == 1 {
avals.push(i-idx);
}
idx = i;
}
}
if a[idx] == 1 {
avals.push(n - idx);
}
for &v in avals.iter() {
result -= calc(v);
}
println!("{}", result);
}