結果

問題 No.832 麻雀修行中
ユーザー 37zigen37zigen
提出日時 2019-05-23 21:30:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,685 bytes
コンパイル時間 2,159 ms
コンパイル使用メモリ 77,852 KB
実行使用メモリ 57,624 KB
最終ジャッジ日時 2023-10-17 11:35:56
合計ジャッジ時間 7,869 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
57,492 KB
testcase_01 AC 125 ms
57,420 KB
testcase_02 AC 122 ms
57,548 KB
testcase_03 AC 123 ms
57,452 KB
testcase_04 AC 121 ms
57,488 KB
testcase_05 AC 121 ms
57,412 KB
testcase_06 AC 123 ms
57,424 KB
testcase_07 AC 124 ms
57,464 KB
testcase_08 AC 124 ms
57,492 KB
testcase_09 AC 123 ms
57,480 KB
testcase_10 AC 124 ms
57,604 KB
testcase_11 AC 112 ms
56,272 KB
testcase_12 AC 124 ms
57,304 KB
testcase_13 AC 114 ms
56,316 KB
testcase_14 AC 125 ms
57,576 KB
testcase_15 AC 125 ms
57,324 KB
testcase_16 AC 124 ms
57,512 KB
testcase_17 AC 123 ms
57,468 KB
testcase_18 AC 124 ms
57,388 KB
testcase_19 AC 125 ms
57,564 KB
testcase_20 AC 121 ms
57,252 KB
testcase_21 AC 124 ms
57,544 KB
testcase_22 AC 129 ms
57,624 KB
testcase_23 AC 124 ms
57,516 KB
testcase_24 AC 123 ms
57,224 KB
testcase_25 AC 125 ms
57,588 KB
testcase_26 AC 123 ms
57,332 KB
testcase_27 AC 123 ms
57,260 KB
testcase_28 AC 113 ms
56,312 KB
testcase_29 AC 125 ms
57,268 KB
testcase_30 AC 127 ms
57,604 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';
		}
		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;
			if (check(i, s)) {
				System.out.println(i);
			}

		}
	}

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

}
0