結果

問題 No.437 cwwゲーム
ユーザー CrazyBBBCrazyBBB
提出日時 2016-10-29 01:13:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,906 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 74,652 KB
実行使用メモリ 50,460 KB
最終ジャッジ日時 2023-08-15 22:06:41
合計ジャッジ時間 5,629 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,500 KB
testcase_01 AC 41 ms
49,572 KB
testcase_02 AC 43 ms
50,332 KB
testcase_03 AC 42 ms
49,660 KB
testcase_04 AC 42 ms
49,552 KB
testcase_05 AC 44 ms
50,312 KB
testcase_06 AC 47 ms
50,460 KB
testcase_07 AC 47 ms
50,152 KB
testcase_08 AC 45 ms
50,160 KB
testcase_09 AC 45 ms
50,228 KB
testcase_10 AC 45 ms
50,304 KB
testcase_11 AC 42 ms
49,676 KB
testcase_12 AC 44 ms
49,868 KB
testcase_13 AC 44 ms
50,308 KB
testcase_14 AC 44 ms
50,408 KB
testcase_15 AC 47 ms
50,308 KB
testcase_16 AC 41 ms
49,360 KB
testcase_17 AC 42 ms
49,516 KB
testcase_18 AC 42 ms
50,228 KB
testcase_19 WA -
testcase_20 AC 44 ms
49,552 KB
testcase_21 AC 42 ms
49,480 KB
testcase_22 AC 43 ms
49,336 KB
testcase_23 AC 44 ms
49,556 KB
testcase_24 AC 44 ms
49,352 KB
testcase_25 AC 43 ms
49,996 KB
testcase_26 AC 43 ms
49,628 KB
testcase_27 AC 43 ms
49,472 KB
testcase_28 AC 43 ms
49,468 KB
testcase_29 AC 43 ms
49,520 KB
testcase_30 AC 42 ms
49,600 KB
testcase_31 AC 43 ms
49,872 KB
testcase_32 AC 42 ms
49,552 KB
testcase_33 AC 43 ms
49,496 KB
testcase_34 AC 43 ms
49,496 KB
testcase_35 AC 43 ms
49,568 KB
testcase_36 AC 42 ms
49,532 KB
testcase_37 AC 42 ms
49,660 KB
testcase_38 AC 42 ms
49,476 KB
testcase_39 AC 44 ms
47,584 KB
testcase_40 AC 44 ms
49,356 KB
testcase_41 AC 44 ms
49,460 KB
testcase_42 AC 43 ms
49,416 KB
testcase_43 AC 44 ms
49,420 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 (dp[y] >= 0) {
                        if (d[i] != d[j] && d[j] == d[k]) {
                            ret = Math.max(ret, t + dp[y]);
                        }
                    } else {
                        if (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