結果

問題 No.634 硬貨の枚数1
ユーザー hiromi_ayasehiromi_ayase
提出日時 2018-01-19 23:24:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 3,038 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 82,644 KB
実行使用メモリ 52,436 KB
最終ジャッジ日時 2024-06-07 14:34:47
合計ジャッジ時間 11,847 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
51,260 KB
testcase_01 AC 78 ms
51,396 KB
testcase_02 AC 79 ms
50,684 KB
testcase_03 AC 79 ms
51,152 KB
testcase_04 AC 78 ms
51,248 KB
testcase_05 AC 78 ms
51,288 KB
testcase_06 AC 78 ms
50,628 KB
testcase_07 AC 76 ms
51,264 KB
testcase_08 AC 77 ms
51,128 KB
testcase_09 AC 77 ms
51,172 KB
testcase_10 AC 77 ms
51,268 KB
testcase_11 AC 77 ms
51,128 KB
testcase_12 AC 76 ms
50,836 KB
testcase_13 AC 76 ms
51,288 KB
testcase_14 AC 94 ms
52,064 KB
testcase_15 AC 105 ms
52,284 KB
testcase_16 AC 106 ms
52,256 KB
testcase_17 AC 110 ms
52,332 KB
testcase_18 AC 105 ms
52,252 KB
testcase_19 AC 104 ms
52,324 KB
testcase_20 AC 110 ms
52,164 KB
testcase_21 AC 113 ms
52,312 KB
testcase_22 AC 100 ms
52,028 KB
testcase_23 AC 107 ms
52,300 KB
testcase_24 AC 76 ms
51,160 KB
testcase_25 AC 78 ms
51,200 KB
testcase_26 AC 78 ms
50,740 KB
testcase_27 AC 80 ms
51,196 KB
testcase_28 AC 78 ms
51,012 KB
testcase_29 AC 80 ms
50,776 KB
testcase_30 AC 78 ms
51,124 KB
testcase_31 AC 79 ms
51,328 KB
testcase_32 AC 78 ms
51,220 KB
testcase_33 AC 77 ms
51,176 KB
testcase_34 AC 90 ms
51,972 KB
testcase_35 AC 107 ms
52,432 KB
testcase_36 AC 113 ms
52,308 KB
testcase_37 AC 107 ms
52,324 KB
testcase_38 AC 97 ms
52,180 KB
testcase_39 AC 107 ms
52,132 KB
testcase_40 AC 104 ms
52,300 KB
testcase_41 AC 109 ms
52,284 KB
testcase_42 AC 108 ms
52,312 KB
testcase_43 AC 109 ms
51,832 KB
testcase_44 AC 77 ms
50,820 KB
testcase_45 AC 79 ms
50,828 KB
testcase_46 AC 95 ms
51,932 KB
testcase_47 AC 111 ms
52,300 KB
testcase_48 AC 79 ms
51,136 KB
testcase_49 AC 89 ms
52,264 KB
testcase_50 AC 108 ms
51,856 KB
testcase_51 AC 96 ms
51,944 KB
testcase_52 AC 77 ms
51,396 KB
testcase_53 AC 76 ms
50,784 KB
testcase_54 AC 76 ms
50,836 KB
testcase_55 AC 115 ms
52,304 KB
testcase_56 AC 109 ms
52,104 KB
testcase_57 AC 112 ms
52,336 KB
testcase_58 AC 111 ms
52,068 KB
testcase_59 AC 110 ms
52,232 KB
testcase_60 AC 110 ms
52,248 KB
testcase_61 AC 109 ms
52,060 KB
testcase_62 AC 116 ms
51,780 KB
testcase_63 AC 114 ms
52,436 KB
testcase_64 AC 110 ms
52,304 KB
testcase_65 AC 114 ms
51,724 KB
testcase_66 AC 110 ms
52,396 KB
testcase_67 AC 115 ms
52,036 KB
testcase_68 AC 113 ms
52,088 KB
testcase_69 AC 111 ms
52,428 KB
testcase_70 AC 114 ms
51,800 KB
testcase_71 AC 113 ms
52,228 KB
testcase_72 AC 98 ms
51,940 KB
testcase_73 AC 108 ms
52,244 KB
testcase_74 AC 105 ms
52,324 KB
testcase_75 AC 110 ms
52,216 KB
testcase_76 AC 76 ms
51,248 KB
testcase_77 AC 78 ms
51,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

public class Main {
  private static void solve() {
    int n = ni();

    System.out.println(f(n));
  }

  private static int f(int n) {
    int m = 5000;
    int[] coin = new int[m];

    for (int i = 1; i < m; i ++) {
      int c = i * (i + 1) / 2;
      if (c > n) {
        m = i;
        break;
      } else {
        coin[i] = c;
      }
    }
    
    boolean two = false;
    for (int i = 0; i < m; i ++) {
      if (coin[i] == n) {
        return 1;
      }

      if (!two) {
        for (int j = i; j < m; j ++) {
          int last = n - coin[i] - coin[j];
          if (last < 0) break;
          else if (last == 0) two = true;;
        }
      }
    }
    return two ? 2 : 3;
  }
  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


0