結果

問題 No.1633 Sorting Integers (Multiple of 2^K)
ユーザー tentententen
提出日時 2023-06-27 09:44:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 2,810 bytes
コンパイル時間 4,370 ms
コンパイル使用メモリ 88,620 KB
実行使用メモリ 52,544 KB
最終ジャッジ日時 2023-09-17 06:45:17
合計ジャッジ時間 8,760 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,344 KB
testcase_01 AC 43 ms
49,288 KB
testcase_02 AC 42 ms
49,344 KB
testcase_03 AC 43 ms
47,436 KB
testcase_04 AC 43 ms
49,344 KB
testcase_05 AC 43 ms
49,328 KB
testcase_06 AC 43 ms
49,416 KB
testcase_07 AC 44 ms
49,248 KB
testcase_08 AC 43 ms
49,380 KB
testcase_09 AC 43 ms
49,656 KB
testcase_10 AC 43 ms
49,236 KB
testcase_11 AC 44 ms
49,256 KB
testcase_12 AC 44 ms
49,252 KB
testcase_13 AC 43 ms
49,404 KB
testcase_14 AC 44 ms
49,332 KB
testcase_15 AC 43 ms
49,328 KB
testcase_16 AC 43 ms
49,364 KB
testcase_17 AC 44 ms
49,332 KB
testcase_18 AC 43 ms
49,364 KB
testcase_19 AC 43 ms
49,252 KB
testcase_20 AC 43 ms
49,372 KB
testcase_21 AC 43 ms
49,788 KB
testcase_22 AC 44 ms
49,660 KB
testcase_23 AC 223 ms
52,468 KB
testcase_24 AC 227 ms
52,276 KB
testcase_25 AC 238 ms
50,444 KB
testcase_26 AC 215 ms
52,256 KB
testcase_27 AC 232 ms
50,376 KB
testcase_28 AC 196 ms
52,060 KB
testcase_29 AC 226 ms
52,344 KB
testcase_30 AC 210 ms
52,256 KB
testcase_31 AC 224 ms
52,164 KB
testcase_32 AC 179 ms
52,160 KB
testcase_33 AC 102 ms
52,060 KB
testcase_34 AC 49 ms
49,540 KB
testcase_35 AC 105 ms
52,016 KB
testcase_36 AC 84 ms
51,500 KB
testcase_37 AC 115 ms
52,404 KB
testcase_38 AC 144 ms
52,348 KB
testcase_39 AC 97 ms
52,276 KB
testcase_40 AC 49 ms
49,312 KB
testcase_41 AC 132 ms
52,148 KB
testcase_42 AC 62 ms
51,196 KB
testcase_43 AC 98 ms
52,076 KB
testcase_44 AC 152 ms
52,460 KB
testcase_45 AC 118 ms
52,544 KB
testcase_46 AC 76 ms
51,132 KB
testcase_47 AC 45 ms
49,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0