結果

問題 No.832 麻雀修行中
ユーザー 37zigen37zigen
提出日時 2019-05-23 21:37:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,893 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 78,660 KB
実行使用メモリ 57,780 KB
最終ジャッジ日時 2023-10-17 11:36:04
合計ジャッジ時間 6,957 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
57,368 KB
testcase_01 AC 121 ms
57,232 KB
testcase_02 AC 123 ms
57,368 KB
testcase_03 AC 123 ms
57,224 KB
testcase_04 AC 117 ms
56,332 KB
testcase_05 AC 122 ms
57,092 KB
testcase_06 AC 123 ms
57,360 KB
testcase_07 AC 122 ms
57,672 KB
testcase_08 AC 122 ms
57,628 KB
testcase_09 AC 124 ms
57,596 KB
testcase_10 AC 112 ms
56,272 KB
testcase_11 AC 123 ms
57,492 KB
testcase_12 AC 125 ms
57,536 KB
testcase_13 AC 123 ms
57,628 KB
testcase_14 AC 122 ms
57,356 KB
testcase_15 AC 125 ms
57,536 KB
testcase_16 AC 123 ms
57,492 KB
testcase_17 AC 124 ms
57,304 KB
testcase_18 AC 125 ms
57,528 KB
testcase_19 AC 125 ms
57,596 KB
testcase_20 AC 124 ms
57,780 KB
testcase_21 AC 126 ms
57,476 KB
testcase_22 AC 128 ms
57,508 KB
testcase_23 AC 127 ms
57,528 KB
testcase_24 AC 125 ms
57,480 KB
testcase_25 AC 125 ms
55,496 KB
testcase_26 AC 126 ms
57,764 KB
testcase_27 AC 125 ms
57,536 KB
testcase_28 AC 125 ms
57,632 KB
testcase_29 AC 125 ms
57,728 KB
testcase_30 AC 125 ms
57,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 制約侵害の有無の確認

import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	boolean check2(int[] cnt) {
		boolean zero = true;
		for (int v : cnt) {
			zero &= v == 0;
		}
		if (zero)
			return true;
		int p = 0;
		while (cnt[p] == 0)
			++p;
		boolean ret = false;
		if (cnt[p] >= 3) {
			cnt[p] -= 3;
			ret |= check2(cnt);
			cnt[p] += 3;
		}
		if (p + 2 <= cnt.length - 1 && cnt[p] > 0 && cnt[p + 1] > 0 && cnt[p + 2] > 0) {
			--cnt[p];
			--cnt[p + 1];
			--cnt[p + 2];
			ret |= check2(cnt);
			++cnt[p];
			++cnt[p + 1];
			++cnt[p + 2];
		}
		return ret;
	}

	boolean check(int num, int[] s) {
		int[] a = new int[s.length + 1];
		for (int i = 0; i < s.length; ++i) {
			a[i] = s[i];
		}
		a[a.length - 1] = num;
		Arrays.sort(a);
		int[] cnt = new int[10];
		for (int v : a) {
			++cnt[v];
		}
		boolean flag = true;
		for (int v : cnt) {
			flag &= v == 2 || v == 0;
		}
		if (flag) // FF, GG, HH, II, JJ, KK, LL型
			return true;
		boolean ret = false;
		for (int i = 0; i <= 9; ++i) {
			if (cnt[i] >= 2) {
				cnt[i] -= 2;
				ret |= check2(cnt);
				cnt[i] += 2;
			}
		}
		return ret;
	}

	void run() throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] cs = sc.next().toCharArray();
		int[] s = new int[cs.length];
		for (int i = 0; i < cs.length; ++i) {
			s[i] = cs[i] - '0';
			if (!(1 <= s[i] && s[i] <= 9))
				throw new AssertionError();
		}
		if (s.length != 13)
			throw new AssertionError();

		Arrays.sort(s);

		for (int i = 1; i <= 9; ++i) {
			int cnt = 0;
			for (int v : s) {
				if (v == i)
					++cnt;
			}
			if (cnt == 4)
				continue;
			else if (cnt > 4)
				throw new AssertionError();
			if (check(i, s)) {
				System.out.println(i);
			}

		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0