結果

問題 No.437 cwwゲーム
ユーザー ぴろず
提出日時 2016-10-28 23:33:18
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 1,323 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 77,772 KB
実行使用メモリ 61,052 KB
最終ジャッジ日時 2024-11-24 06:28:57
合計ジャッジ時間 14,822 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 1 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

package no437;

import java.util.Arrays;
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 m = (n + 2) / 3;
		int[] p = new int[n];
		int[] a = new int[m];
		int max = 0;
		LOOP: do {
			if (p[n-1] >= 1) break;
			int score = 0;
			Arrays.fill(a, 0);
			int count = 0;
			for(int i=0;i<n;i++) {
				if (count >= 2) continue LOOP;
				int j = p[i];
				int c = x[i];
				if (a[j] == 0 && c == 0) {
					count++;
					continue;
				}
				if (a[j] >= 100) {
					count++;
					continue;
				}
				a[j] = a[j] * 10 + c;
			}
			for(int i=0;i<m;i++) {
				if (!isCWW[a[i]]) {
					continue;
				}
				score += a[i];
			}
//			if (max < score) {
//				System.out.println(score + " " + Arrays.toString(a));
//			}
			max = Math.max(max, score);
		} while (nextSequence(p, m));
		System.out.println(max);
	}
	public static boolean nextSequence(int[] s, int k) {
		int n = s.length;
		for(int i=0;i<n;i++) {
			s[i]++;
			if (s[i] < k) {
				return true;
			}
			s[i] = 0;
		}
		return false;
	}
}
0