結果

問題 No.2142 Segment Zero
ユーザー phspls
提出日時 2022-12-04 18:45:26
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 14,040 ms
コンパイル使用メモリ 379,432 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 20:59:31
合計ジャッジ時間 13,281 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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];

    let summary = n * (n+1) / 2;
    if k == summary {
        println!("0");
        return;
    } else if k == 0 {
        println!("1");
        return;
    }
    let k = summary - k;
    let mut summary = 0usize;
    let mut lidx = 0usize;
    for i in 0..n {
        summary += i;
        while lidx < n && summary > k {
            lidx += 1;
            summary -= lidx;
        }
        if summary == k {
            println!("1");
            return;
        }
    }
    println!("2");
}
0