結果

問題 No.437 cwwゲーム
ユーザー crazybbb3crazybbb3
提出日時 2016-10-29 12:32:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 2,672 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 78,488 KB
実行使用メモリ 37,452 KB
最終ジャッジ日時 2024-04-20 13:07:09
合計ジャッジ時間 5,749 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
37,000 KB
testcase_01 AC 55 ms
37,160 KB
testcase_02 AC 55 ms
36,884 KB
testcase_03 AC 52 ms
37,252 KB
testcase_04 AC 54 ms
37,204 KB
testcase_05 AC 53 ms
37,204 KB
testcase_06 AC 53 ms
37,452 KB
testcase_07 AC 55 ms
37,348 KB
testcase_08 AC 54 ms
37,376 KB
testcase_09 AC 55 ms
37,316 KB
testcase_10 AC 55 ms
37,316 KB
testcase_11 AC 56 ms
37,360 KB
testcase_12 AC 55 ms
36,860 KB
testcase_13 AC 52 ms
36,828 KB
testcase_14 AC 53 ms
37,376 KB
testcase_15 AC 56 ms
37,000 KB
testcase_16 AC 52 ms
36,852 KB
testcase_17 AC 53 ms
37,376 KB
testcase_18 AC 53 ms
37,392 KB
testcase_19 AC 52 ms
36,872 KB
testcase_20 AC 52 ms
37,296 KB
testcase_21 AC 53 ms
37,356 KB
testcase_22 AC 53 ms
36,952 KB
testcase_23 AC 55 ms
37,356 KB
testcase_24 AC 53 ms
37,264 KB
testcase_25 AC 52 ms
37,200 KB
testcase_26 AC 54 ms
36,884 KB
testcase_27 AC 52 ms
37,396 KB
testcase_28 AC 52 ms
37,204 KB
testcase_29 AC 52 ms
37,296 KB
testcase_30 AC 53 ms
37,364 KB
testcase_31 AC 52 ms
36,892 KB
testcase_32 AC 53 ms
37,376 KB
testcase_33 AC 54 ms
36,844 KB
testcase_34 AC 53 ms
36,892 KB
testcase_35 AC 52 ms
37,200 KB
testcase_36 AC 54 ms
37,396 KB
testcase_37 AC 53 ms
37,376 KB
testcase_38 AC 54 ms
37,316 KB
testcase_39 AC 54 ms
37,296 KB
testcase_40 AC 54 ms
37,264 KB
testcase_41 AC 55 ms
37,204 KB
testcase_42 AC 54 ms
37,072 KB
testcase_43 AC 54 ms
36,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    int n;
    int[] dp;
    int[] d;

    void solve() throws IOException {
        char[] s = ns().toCharArray();

        n = s.length;
        dp = new int[1 << n];
        Arrays.fill(dp, -1);
        d = new int[n];
        for (int i = 0; i < n; i++) {
            d[i] = s[i] - '0';
        }
        out.println(calc(0));
    }

    int calc(int x) {
        if (Integer.bitCount(x) > n - 3) return 0;
        if (dp[x] >= 0) return dp[x];

        int ret = 0;
        for (int i = 0; i < n - 2; i++) {
            if (((x >> i) & 1) == 1) continue;
            for (int j = i + 1; j < n - 1; j++) {
                if (((x >> j) & 1) == 1) continue;
                for (int k = j + 1; k < n; k++) {
                    if (((x >> k) & 1) == 1) continue;
                    int y = x | (1 << i) | (1 << j) | (1 << k);
                    int t = d[i] * 100 + d[j] * 10 + d[k];
                    if (d[i] != 0 && d[i] != d[j] && d[j] == d[k]) {
                        ret = Math.max(ret, t + calc(y));
                    }
                }
            }
        }

        return dp[x] = ret;
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0