結果

問題 No.634 硬貨の枚数1
ユーザー ixTL255
提出日時 2023-01-02 22:27:56
言語 Rust
(1.83.0 + proconio)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 532 bytes
コンパイル時間 13,381 ms
コンパイル使用メモリ 383,844 KB
実行使用メモリ 227,628 KB
最終ジャッジ日時 2024-11-27 01:22:49
合計ジャッジ時間 78,338 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 58 TLE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashSet;

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

	let mut t: Vec<usize> = vec![1];
	
	for i in 2.. {
		if i < n { t.push(t[i - 2] + i); }
		else { break; }
	}

	let set: HashSet<usize> = t.iter().cloned().collect();

	let mut ans = 3;
	if set.contains(&n) {
		println!("{}", 1);
		return;
	}

	for i in 0..set.len() {
		if set.contains(&(n - t[i])) {
			ans = 2;
		}
		if t[i] > n / 2 { break; }
	}

	println!("{}", ans);
}
0