結果

問題 No.437 cwwゲーム
ユーザー ぴろずぴろず
提出日時 2016-10-28 23:44:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 2,624 ms
コンパイル使用メモリ 77,228 KB
実行使用メモリ 54,636 KB
最終ジャッジ日時 2024-04-20 13:02:22
合計ジャッジ時間 10,277 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
54,400 KB
testcase_01 AC 129 ms
54,056 KB
testcase_02 AC 136 ms
54,300 KB
testcase_03 AC 135 ms
54,636 KB
testcase_04 AC 136 ms
54,344 KB
testcase_05 AC 149 ms
53,824 KB
testcase_06 AC 151 ms
54,496 KB
testcase_07 AC 150 ms
54,488 KB
testcase_08 AC 149 ms
54,184 KB
testcase_09 AC 151 ms
54,020 KB
testcase_10 AC 152 ms
54,428 KB
testcase_11 AC 158 ms
54,172 KB
testcase_12 AC 155 ms
54,108 KB
testcase_13 AC 169 ms
54,072 KB
testcase_14 AC 144 ms
54,432 KB
testcase_15 AC 152 ms
54,276 KB
testcase_16 AC 150 ms
54,380 KB
testcase_17 AC 147 ms
54,520 KB
testcase_18 AC 142 ms
54,404 KB
testcase_19 AC 135 ms
54,164 KB
testcase_20 AC 133 ms
54,508 KB
testcase_21 AC 137 ms
53,872 KB
testcase_22 AC 135 ms
54,072 KB
testcase_23 AC 162 ms
54,420 KB
testcase_24 AC 135 ms
54,232 KB
testcase_25 AC 162 ms
54,400 KB
testcase_26 AC 161 ms
54,228 KB
testcase_27 AC 134 ms
54,128 KB
testcase_28 AC 134 ms
54,424 KB
testcase_29 AC 130 ms
54,068 KB
testcase_30 AC 133 ms
54,092 KB
testcase_31 AC 133 ms
54,104 KB
testcase_32 AC 136 ms
54,140 KB
testcase_33 AC 143 ms
54,312 KB
testcase_34 AC 129 ms
54,376 KB
testcase_35 AC 134 ms
54,296 KB
testcase_36 AC 130 ms
53,884 KB
testcase_37 AC 131 ms
54,352 KB
testcase_38 AC 133 ms
54,608 KB
testcase_39 AC 131 ms
53,744 KB
testcase_40 AC 134 ms
54,280 KB
testcase_41 AC 138 ms
54,272 KB
testcase_42 AC 141 ms
54,220 KB
testcase_43 AC 142 ms
54,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no437;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		boolean[] isCWW = new boolean[1000];
		for(int i=100;i<1000;i++) {
			isCWW[i] = i % 111 != 0 && i % 100 % 11 == 0;
		}
		int[] x = new int[n];
		for(int i=0;i<n;i++) {
			x[i] = s.charAt(i) - '0';
		}
		int[] dp = new int[1<<n];
		for(int m=0;m<1<<n;m++) {
			for(int i=0;i<n;i++) {
				if ((m >> i & 1) == 1) continue;
				for(int j=i+1;j<n;j++) {
					if ((m >> j & 1) == 1) continue;
					for(int k=j+1;k<n;k++) {
						if ((m >> k & 1) == 1) continue;
						int a = x[i] * 100 + x[j] * 10 + x[k];
						if (!isCWW[a]) continue;
						int nm = m | (1 << i) | (1 << j) | (1 << k);
						dp[nm] = Math.max(dp[nm], dp[m] + a);
					}
				}
			}
		}
		int max = 0;
		for(int i=0;i<1<<n;i++) {
			max = Math.max(max, dp[i]);
		}
		System.out.println(max);
	}
}
0