結果
| 問題 | No.2142 Segment Zero |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-17 17:08:21 |
| 言語 | Rust (1.99.0 + proconio + num + itertools + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 4 ms / 2,000 ms |
| + 65µs | |
| コード長 | 726 bytes |
| 記録 | |
| コンパイル時間 | 690 ms |
| コンパイル使用メモリ | 174,432 KB |
| 実行使用メモリ | 9,900 KB |
| 最終ジャッジ日時 | 2026-10-16 16:23:37 |
| 合計ジャッジ時間 | 3,188 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
fn main() {
let mut nk = String::new();
std::io::stdin().read_line(&mut nk).ok();
let nk: Vec<usize> = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
let n = nk[0];
let k = nk[1];
if k == n * (n+1) / 2 {
println!("0");
return;
} if k == 0 {
println!("1");
return;
}
let k = n * (n+1) / 2 - k;
let a = (1..=n).collect::<Vec<_>>();
let mut idx = 0usize;
let mut summary = 0usize;
for i in 0..n {
summary += a[i];
while summary > k {
summary -= a[idx];
idx += 1;
}
if k == summary {
println!("1");
return;
}
}
println!("2");
}