結果

問題 No.634 硬貨の枚数1
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-19 21:46:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,405 bytes
コンパイル時間 3,591 ms
コンパイル使用メモリ 76,048 KB
実行使用メモリ 95,388 KB
最終ジャッジ日時 2023-08-26 18:28:24
合計ジャッジ時間 10,781 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
93,388 KB
testcase_01 AC 69 ms
93,164 KB
testcase_02 AC 72 ms
93,304 KB
testcase_03 AC 72 ms
93,072 KB
testcase_04 AC 73 ms
92,972 KB
testcase_05 AC 74 ms
93,320 KB
testcase_06 AC 74 ms
93,180 KB
testcase_07 AC 73 ms
93,056 KB
testcase_08 AC 73 ms
93,056 KB
testcase_09 AC 74 ms
93,360 KB
testcase_10 AC 73 ms
93,240 KB
testcase_11 AC 72 ms
93,100 KB
testcase_12 AC 75 ms
93,176 KB
testcase_13 AC 70 ms
93,096 KB
testcase_14 AC 75 ms
93,084 KB
testcase_15 AC 73 ms
93,208 KB
testcase_16 AC 76 ms
93,008 KB
testcase_17 AC 76 ms
95,388 KB
testcase_18 AC 73 ms
93,304 KB
testcase_19 AC 76 ms
93,408 KB
testcase_20 AC 73 ms
93,052 KB
testcase_21 AC 73 ms
92,968 KB
testcase_22 AC 74 ms
93,172 KB
testcase_23 AC 74 ms
93,316 KB
testcase_24 AC 75 ms
93,156 KB
testcase_25 AC 72 ms
93,640 KB
testcase_26 AC 73 ms
93,052 KB
testcase_27 AC 73 ms
93,204 KB
testcase_28 AC 72 ms
93,228 KB
testcase_29 AC 71 ms
93,360 KB
testcase_30 AC 73 ms
93,056 KB
testcase_31 AC 73 ms
93,412 KB
testcase_32 AC 72 ms
93,160 KB
testcase_33 AC 74 ms
93,124 KB
testcase_34 AC 75 ms
93,132 KB
testcase_35 AC 75 ms
93,124 KB
testcase_36 AC 74 ms
93,056 KB
testcase_37 AC 75 ms
93,164 KB
testcase_38 AC 75 ms
93,520 KB
testcase_39 AC 72 ms
93,116 KB
testcase_40 AC 77 ms
93,100 KB
testcase_41 AC 75 ms
93,168 KB
testcase_42 AC 76 ms
93,052 KB
testcase_43 AC 74 ms
93,040 KB
testcase_44 AC 74 ms
93,220 KB
testcase_45 AC 79 ms
93,208 KB
testcase_46 AC 74 ms
93,128 KB
testcase_47 AC 77 ms
93,240 KB
testcase_48 AC 70 ms
93,212 KB
testcase_49 AC 75 ms
93,208 KB
testcase_50 AC 79 ms
93,316 KB
testcase_51 AC 76 ms
93,364 KB
testcase_52 AC 75 ms
93,452 KB
testcase_53 AC 73 ms
93,244 KB
testcase_54 AC 73 ms
93,100 KB
testcase_55 AC 76 ms
93,124 KB
testcase_56 AC 76 ms
93,180 KB
testcase_57 AC 77 ms
93,072 KB
testcase_58 AC 77 ms
93,388 KB
testcase_59 AC 74 ms
92,972 KB
testcase_60 AC 75 ms
93,376 KB
testcase_61 AC 76 ms
93,124 KB
testcase_62 AC 76 ms
93,116 KB
testcase_63 AC 79 ms
93,172 KB
testcase_64 AC 78 ms
93,232 KB
testcase_65 AC 75 ms
90,928 KB
testcase_66 AC 74 ms
93,508 KB
testcase_67 AC 77 ms
93,684 KB
testcase_68 AC 74 ms
93,204 KB
testcase_69 AC 77 ms
93,200 KB
testcase_70 AC 76 ms
93,364 KB
testcase_71 AC 73 ms
93,364 KB
testcase_72 AC 74 ms
93,176 KB
testcase_73 AC 76 ms
93,068 KB
testcase_74 AC 73 ms
92,980 KB
testcase_75 AC 73 ms
93,440 KB
testcase_76 AC 74 ms
93,240 KB
testcase_77 AC 71 ms
93,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    static final int I=1<<27;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        final int W=10000000;
        int[]dp=new int[W];
        Arrays.fill(dp,I);
        dp[0]=0;
        final int B=5000;
        int[]t=new int[B];
        Set<Integer> ts=new HashSet<Integer>();
        for(int i=1;i<5000;++i){
            int w=i*(i+1)/2;
            t[i]=w;
            ts.add(w);
            if(t[i]==n){
                out.println(1);
                out.close();
                return;
            }
        }
        for(int i=0;i<B;++i){
            int rest=n-t[i];
            if(rest<=0){
                continue;
            }
            if(ts.contains(rest)){
                out.println(2);
                out.close();
                return;
            }
        }
        out.println(3);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}
0