結果
| 問題 |
No.1148 土偶Ⅲ
|
| ユーザー |
|
| 提出日時 | 2020-08-12 20:58:52 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,092 bytes |
| コンパイル時間 | 12,591 ms |
| コンパイル使用メモリ | 383,632 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-09 18:35:14 |
| 合計ジャッジ時間 | 13,967 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
use std::cmp::max;
use std::collections::HashMap;
fn main() {
let mut nw = String::new();
std::io::stdin().read_line(&mut nw).ok();
let nw: Vec<usize> = nw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
let n = nw[0];
let w = nw[1];
let mut a: Vec<usize> = vec![];
for _ in 0..n {
let mut tempa = String::new();
std::io::stdin().read_line(&mut tempa).ok();
let tempa: usize = tempa.trim().parse().unwrap();
a.push(tempa);
}
let mut result = 0usize;
let mut val: usize = 0usize;
let mut used: HashMap<usize, usize> = HashMap::new();
let mut sidx = 0usize;
for i in 0..n {
val += a[i];
if let Some(x) = used.get_mut(&a[i]) {
while sidx <= *x {
val -= a[sidx];
sidx += 1;
}
*x = i;
} else {
used.insert(a[i], i);
}
while w < val {
val -= a[sidx];
sidx += 1;
}
result = max(result, i + 1 - sidx);
}
println!("{}", result);
}