結果

問題 No.634 硬貨の枚数1
ユーザー phspls
提出日時 2023-01-08 01:59:46
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 12,669 ms
コンパイル使用メモリ 384,796 KB
実行使用メモリ 11,588 KB
最終ジャッジ日時 2024-12-15 03:34:45
合計ジャッジ時間 13,032 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::collections::VecDeque`
 --> src/main.rs:1:5
  |
1 | use std::collections::VecDeque;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::collections::VecDeque;


fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();

    let mut cands = vec![false; n+1];
    for i in 1.. {
        let val = i * (i+1) / 2;
        if val > n { break; }
        if val == n {
            println!("1");
            return;
        }
        cands[n-val] = true;
    }
    for i in 1.. {
        let val = i * (i+1) / 2;
        if val > n { break; }
        if cands[val] {
            println!("2");
            return;
        }
    }
    println!("3");
}
0