結果

問題 No.2142 Segment Zero
ユーザー phsplsphspls
提出日時 2022-12-04 18:44:20
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 13,292 ms
コンパイル使用メモリ 395,032 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-11 20:58:50
合計ジャッジ時間 14,743 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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;
    }
    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