結果
問題 | No.1633 Sorting Integers (Multiple of 2^K) |
ユーザー | tenten |
提出日時 | 2023-06-27 09:44:17 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 240 ms / 2,000 ms |
コード長 | 2,810 bytes |
コンパイル時間 | 2,516 ms |
コンパイル使用メモリ | 85,236 KB |
実行使用メモリ | 39,656 KB |
最終ジャッジ日時 | 2024-07-04 03:47:55 |
合計ジャッジ時間 | 8,443 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
36,972 KB |
testcase_01 | AC | 46 ms
36,980 KB |
testcase_02 | AC | 45 ms
36,972 KB |
testcase_03 | AC | 45 ms
37,136 KB |
testcase_04 | AC | 46 ms
37,320 KB |
testcase_05 | AC | 50 ms
37,088 KB |
testcase_06 | AC | 45 ms
36,784 KB |
testcase_07 | AC | 45 ms
37,412 KB |
testcase_08 | AC | 45 ms
37,228 KB |
testcase_09 | AC | 46 ms
36,808 KB |
testcase_10 | AC | 45 ms
36,984 KB |
testcase_11 | AC | 44 ms
37,192 KB |
testcase_12 | AC | 45 ms
37,236 KB |
testcase_13 | AC | 46 ms
36,752 KB |
testcase_14 | AC | 47 ms
36,852 KB |
testcase_15 | AC | 47 ms
36,784 KB |
testcase_16 | AC | 47 ms
37,156 KB |
testcase_17 | AC | 46 ms
36,788 KB |
testcase_18 | AC | 45 ms
36,744 KB |
testcase_19 | AC | 44 ms
37,252 KB |
testcase_20 | AC | 46 ms
36,676 KB |
testcase_21 | AC | 47 ms
36,664 KB |
testcase_22 | AC | 49 ms
37,204 KB |
testcase_23 | AC | 221 ms
39,576 KB |
testcase_24 | AC | 233 ms
39,284 KB |
testcase_25 | AC | 240 ms
39,284 KB |
testcase_26 | AC | 223 ms
39,140 KB |
testcase_27 | AC | 229 ms
39,656 KB |
testcase_28 | AC | 206 ms
39,640 KB |
testcase_29 | AC | 227 ms
39,152 KB |
testcase_30 | AC | 210 ms
39,560 KB |
testcase_31 | AC | 225 ms
39,116 KB |
testcase_32 | AC | 178 ms
39,648 KB |
testcase_33 | AC | 102 ms
39,372 KB |
testcase_34 | AC | 49 ms
37,068 KB |
testcase_35 | AC | 101 ms
39,088 KB |
testcase_36 | AC | 83 ms
38,184 KB |
testcase_37 | AC | 111 ms
39,260 KB |
testcase_38 | AC | 146 ms
39,348 KB |
testcase_39 | AC | 104 ms
39,280 KB |
testcase_40 | AC | 53 ms
36,968 KB |
testcase_41 | AC | 136 ms
39,364 KB |
testcase_42 | AC | 69 ms
37,372 KB |
testcase_43 | AC | 105 ms
39,112 KB |
testcase_44 | AC | 152 ms
39,600 KB |
testcase_45 | AC | 121 ms
39,392 KB |
testcase_46 | AC | 78 ms
38,196 KB |
testcase_47 | AC | 47 ms
37,116 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int ans = 0; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] counts = new int[10]; for (int i = 1; i < 10; i++) { counts[i] = sc.nextInt(); } getCount(n, 0, counts, 0); System.out.println(ans); } static void getCount(int idx, int v, int[] counts, long current) { if (idx == 0) { ans = Math.max(ans, getCount(current)); } long by = pow(10, v); for (int i = 1; i < 10; i++) { if (counts[i] == 0) { continue; } counts[i]--; long next = current + i * by; int tmp = getCount(next, v + 1); ans = Math.max(ans, tmp); if (tmp >= v + 1) { getCount(idx - 1, v + 1, counts, next); } counts[i]++; } } static int getCount(long x) { int count = 0; while (x > 0 && x % 2 == 0) { count++; x >>= 1; } return count; } static int getCount(long x, int max) { int count = 0; for (int i = 0; i < max && x > 0 && x % 2 == 0; i++) { count++; x >>= 1; } return count; } static long pow(long x, int p) { if (p == 0) { return 1; } else { return pow(x, p - 1) * x; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }