結果
| 問題 | No.1505 Zero-Product Ranges |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-16 04:07:19 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,025 bytes |
| 記録 | |
| コンパイル時間 | 12,179 ms |
| コンパイル使用メモリ | 378,932 KB |
| 実行使用メモリ | 13,640 KB |
| 最終ジャッジ日時 | 2024-11-22 15:40:25 |
| 合計ジャッジ時間 | 61,670 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 TLE * 13 |
ソースコード
#[macro_export]
macro_rules! setup {
{ mut $input:ident: SplitWhitespace $(,)? } => {
use std::io::Read;
let mut buf = String::new();
std::io::stdin().read_to_string(&mut buf).ok();
let mut $input = buf.split_whitespace();
};
}
#[macro_export]
macro_rules! parse_next {
($str_iter:expr) => {
$str_iter.next().unwrap().parse().ok().unwrap()
};
}
fn main() {
setup! { mut input: SplitWhitespace };
let n: usize = parse_next!(input);
let a: Vec<usize> = (0..n).map(|_| parse_next!(input)).collect();
let zeros = a
.iter()
.enumerate()
.filter(|(_, x)| **x == 0)
.map(|(i, _)| i)
.collect::<Vec<_>>();
let ans = (|| {
(0..n).fold(0, |acc, l| match a[l] == 0 {
true => acc + (n - l),
false => match zeros.iter().filter(|i| **i >= l).nth(0) {
Some(i) => acc + (n - i),
None => acc,
},
})
})();
println!("{}", ans);
}