結果

問題 No.2142 Segment Zero
ユーザー phspls
提出日時 2022-12-17 17:08:21
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 726 bytes
コンパイル時間 13,637 ms
コンパイル使用メモリ 378,568 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-11-17 02:19:56
合計ジャッジ時間 14,586 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

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");
}
0