結果

問題 No.634 硬貨の枚数1
ユーザー hiromi_ayasehiromi_ayase
提出日時 2018-01-19 23:23:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,042 bytes
コンパイル時間 2,458 ms
コンパイル使用メモリ 82,732 KB
実行使用メモリ 53,212 KB
最終ジャッジ日時 2024-06-07 14:34:23
合計ジャッジ時間 12,106 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
51,184 KB
testcase_01 AC 78 ms
51,124 KB
testcase_02 AC 79 ms
50,928 KB
testcase_03 AC 78 ms
51,156 KB
testcase_04 AC 80 ms
53,212 KB
testcase_05 AC 79 ms
50,992 KB
testcase_06 AC 79 ms
51,192 KB
testcase_07 AC 79 ms
50,684 KB
testcase_08 AC 80 ms
51,188 KB
testcase_09 AC 79 ms
50,768 KB
testcase_10 AC 79 ms
51,100 KB
testcase_11 AC 80 ms
51,068 KB
testcase_12 AC 78 ms
50,840 KB
testcase_13 AC 78 ms
50,692 KB
testcase_14 AC 95 ms
52,168 KB
testcase_15 AC 113 ms
52,096 KB
testcase_16 AC 109 ms
51,924 KB
testcase_17 AC 110 ms
52,084 KB
testcase_18 AC 109 ms
52,360 KB
testcase_19 AC 107 ms
52,348 KB
testcase_20 AC 111 ms
52,128 KB
testcase_21 AC 120 ms
52,292 KB
testcase_22 AC 108 ms
52,088 KB
testcase_23 AC 113 ms
52,260 KB
testcase_24 AC 84 ms
50,720 KB
testcase_25 AC 82 ms
51,172 KB
testcase_26 AC 89 ms
50,852 KB
testcase_27 AC 83 ms
51,208 KB
testcase_28 AC 83 ms
51,072 KB
testcase_29 AC 84 ms
51,180 KB
testcase_30 AC 80 ms
51,288 KB
testcase_31 AC 80 ms
51,048 KB
testcase_32 AC 79 ms
51,284 KB
testcase_33 AC 80 ms
51,180 KB
testcase_34 AC 88 ms
51,472 KB
testcase_35 AC 110 ms
51,856 KB
testcase_36 AC 111 ms
52,280 KB
testcase_37 AC 113 ms
51,732 KB
testcase_38 AC 98 ms
52,108 KB
testcase_39 AC 113 ms
52,252 KB
testcase_40 AC 111 ms
52,072 KB
testcase_41 AC 113 ms
52,232 KB
testcase_42 AC 113 ms
52,236 KB
testcase_43 AC 111 ms
52,272 KB
testcase_44 AC 81 ms
51,240 KB
testcase_45 AC 82 ms
50,836 KB
testcase_46 AC 97 ms
51,824 KB
testcase_47 AC 115 ms
52,136 KB
testcase_48 AC 79 ms
50,956 KB
testcase_49 AC 92 ms
51,896 KB
testcase_50 AC 115 ms
52,452 KB
testcase_51 AC 96 ms
52,196 KB
testcase_52 WA -
testcase_53 AC 82 ms
51,176 KB
testcase_54 AC 79 ms
50,804 KB
testcase_55 AC 114 ms
52,396 KB
testcase_56 AC 113 ms
51,836 KB
testcase_57 AC 115 ms
52,136 KB
testcase_58 AC 120 ms
52,212 KB
testcase_59 AC 114 ms
51,904 KB
testcase_60 AC 112 ms
52,216 KB
testcase_61 AC 115 ms
51,796 KB
testcase_62 AC 113 ms
52,228 KB
testcase_63 AC 115 ms
52,152 KB
testcase_64 AC 116 ms
52,088 KB
testcase_65 AC 123 ms
52,296 KB
testcase_66 AC 109 ms
52,068 KB
testcase_67 AC 112 ms
52,236 KB
testcase_68 AC 115 ms
52,228 KB
testcase_69 AC 114 ms
52,308 KB
testcase_70 AC 113 ms
52,256 KB
testcase_71 AC 115 ms
52,084 KB
testcase_72 AC 103 ms
52,208 KB
testcase_73 AC 111 ms
52,404 KB
testcase_74 AC 111 ms
51,828 KB
testcase_75 AC 114 ms
51,752 KB
testcase_76 AC 78 ms
51,252 KB
testcase_77 AC 77 ms
51,204 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 + 1; 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