結果

問題 No.437 cwwゲーム
ユーザー ぴろずぴろず
提出日時 2016-10-28 23:44:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 3,056 ms
コンパイル使用メモリ 74,032 KB
実行使用メモリ 56,192 KB
最終ジャッジ日時 2023-08-02 12:56:40
合計ジャッジ時間 10,234 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,652 KB
testcase_01 AC 117 ms
55,264 KB
testcase_02 AC 122 ms
55,512 KB
testcase_03 AC 116 ms
55,488 KB
testcase_04 AC 117 ms
56,084 KB
testcase_05 AC 130 ms
55,872 KB
testcase_06 AC 131 ms
55,808 KB
testcase_07 AC 131 ms
56,192 KB
testcase_08 AC 131 ms
55,376 KB
testcase_09 AC 131 ms
55,720 KB
testcase_10 AC 131 ms
55,736 KB
testcase_11 AC 131 ms
55,540 KB
testcase_12 AC 138 ms
55,696 KB
testcase_13 AC 137 ms
55,480 KB
testcase_14 AC 130 ms
55,388 KB
testcase_15 AC 150 ms
55,612 KB
testcase_16 AC 138 ms
55,724 KB
testcase_17 AC 128 ms
55,624 KB
testcase_18 AC 130 ms
55,268 KB
testcase_19 AC 124 ms
55,520 KB
testcase_20 AC 127 ms
55,784 KB
testcase_21 AC 123 ms
55,460 KB
testcase_22 AC 119 ms
55,832 KB
testcase_23 AC 135 ms
55,676 KB
testcase_24 AC 120 ms
55,672 KB
testcase_25 AC 135 ms
55,656 KB
testcase_26 AC 134 ms
55,544 KB
testcase_27 AC 117 ms
55,640 KB
testcase_28 AC 118 ms
55,240 KB
testcase_29 AC 116 ms
55,256 KB
testcase_30 AC 116 ms
55,520 KB
testcase_31 AC 116 ms
55,536 KB
testcase_32 AC 116 ms
55,768 KB
testcase_33 AC 121 ms
55,640 KB
testcase_34 AC 117 ms
55,436 KB
testcase_35 AC 122 ms
55,788 KB
testcase_36 AC 117 ms
55,520 KB
testcase_37 AC 117 ms
55,668 KB
testcase_38 AC 118 ms
55,452 KB
testcase_39 AC 120 ms
55,480 KB
testcase_40 AC 119 ms
55,756 KB
testcase_41 AC 122 ms
55,528 KB
testcase_42 AC 123 ms
55,472 KB
testcase_43 AC 124 ms
55,608 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