結果

問題 No.437 cwwゲーム
ユーザー CrazyBBBCrazyBBB
提出日時 2016-10-29 01:14:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 2,672 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 77,472 KB
実行使用メモリ 37,220 KB
最終ジャッジ日時 2024-04-20 13:04:38
合計ジャッジ時間 5,305 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
37,028 KB
testcase_01 AC 46 ms
36,752 KB
testcase_02 AC 46 ms
37,164 KB
testcase_03 AC 45 ms
36,888 KB
testcase_04 AC 45 ms
37,000 KB
testcase_05 AC 45 ms
37,136 KB
testcase_06 AC 46 ms
36,664 KB
testcase_07 AC 49 ms
37,144 KB
testcase_08 AC 46 ms
37,220 KB
testcase_09 AC 48 ms
37,040 KB
testcase_10 AC 52 ms
36,892 KB
testcase_11 AC 46 ms
37,192 KB
testcase_12 AC 46 ms
36,784 KB
testcase_13 AC 47 ms
36,800 KB
testcase_14 AC 47 ms
37,000 KB
testcase_15 AC 49 ms
37,144 KB
testcase_16 AC 47 ms
37,212 KB
testcase_17 AC 47 ms
36,828 KB
testcase_18 AC 48 ms
36,876 KB
testcase_19 AC 47 ms
37,064 KB
testcase_20 AC 45 ms
36,852 KB
testcase_21 AC 45 ms
36,828 KB
testcase_22 AC 45 ms
37,028 KB
testcase_23 AC 47 ms
36,856 KB
testcase_24 AC 46 ms
36,996 KB
testcase_25 AC 48 ms
37,012 KB
testcase_26 AC 46 ms
37,040 KB
testcase_27 AC 46 ms
36,972 KB
testcase_28 AC 46 ms
37,120 KB
testcase_29 AC 46 ms
36,968 KB
testcase_30 AC 46 ms
37,180 KB
testcase_31 AC 46 ms
37,000 KB
testcase_32 AC 48 ms
36,924 KB
testcase_33 AC 48 ms
36,976 KB
testcase_34 AC 46 ms
36,972 KB
testcase_35 AC 46 ms
37,052 KB
testcase_36 AC 48 ms
36,884 KB
testcase_37 AC 48 ms
37,068 KB
testcase_38 AC 47 ms
37,084 KB
testcase_39 AC 48 ms
36,928 KB
testcase_40 AC 47 ms
37,188 KB
testcase_41 AC 48 ms
37,220 KB
testcase_42 AC 48 ms
36,860 KB
testcase_43 AC 47 ms
36,892 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