結果

問題 No.634 硬貨の枚数1
ユーザー しらっ亭
提出日時 2017-05-17 17:15:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 735 bytes
コンパイル時間 6,166 ms
コンパイル使用メモリ 75,380 KB
実行使用メモリ 42,288 KB
最終ジャッジ日時 2024-12-25 18:36:05
合計ジャッジ時間 14,295 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.HashSet;
import java.util.ArrayList;

public class Main {
    static int solve(int n) {
        HashSet<Integer> exists = new HashSet<>();

        ArrayList<Integer> ts = new ArrayList<>();
        for (int t, i = 1; (t = i * (i + 1) / 2) <= n; i++) {
            if (t == n) {
                return 1;
            }
            ts.add(t);
            exists.add(t);
        }

        for (int t : ts) {
            if (exists.contains(n - t)) {
                return 2;
            }
        }

        return 3;
    }

    public static void main(String... argv) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(solve(n));
    }
}
0