結果

問題 No.832 麻雀修行中
ユーザー YamaKasaYamaKasa
提出日時 2019-05-24 22:31:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 2,059 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 80,328 KB
実行使用メモリ 57,940 KB
最終ジャッジ日時 2023-10-17 12:56:08
合計ジャッジ時間 8,053 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,124 KB
testcase_01 AC 147 ms
57,376 KB
testcase_02 AC 126 ms
57,168 KB
testcase_03 AC 141 ms
57,528 KB
testcase_04 AC 146 ms
57,488 KB
testcase_05 AC 149 ms
57,784 KB
testcase_06 AC 145 ms
57,856 KB
testcase_07 AC 147 ms
57,364 KB
testcase_08 AC 148 ms
57,940 KB
testcase_09 AC 143 ms
57,632 KB
testcase_10 AC 147 ms
57,404 KB
testcase_11 AC 147 ms
57,552 KB
testcase_12 AC 146 ms
57,560 KB
testcase_13 AC 114 ms
56,176 KB
testcase_14 AC 142 ms
57,372 KB
testcase_15 AC 146 ms
57,328 KB
testcase_16 AC 125 ms
57,468 KB
testcase_17 AC 130 ms
57,292 KB
testcase_18 AC 149 ms
57,812 KB
testcase_19 AC 145 ms
57,360 KB
testcase_20 AC 134 ms
57,192 KB
testcase_21 AC 146 ms
57,548 KB
testcase_22 AC 127 ms
57,452 KB
testcase_23 AC 129 ms
57,468 KB
testcase_24 AC 147 ms
57,936 KB
testcase_25 AC 126 ms
57,152 KB
testcase_26 AC 128 ms
57,588 KB
testcase_27 AC 149 ms
57,904 KB
testcase_28 AC 127 ms
57,488 KB
testcase_29 AC 127 ms
57,280 KB
testcase_30 AC 127 ms
57,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.HashSet;
import java.util.Set;

public class Main{
	static int[] b = new int [10];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String s = sc.next();
			//if(s.length() == 1) break;
			int[] a = new int[14];
			int[] c = new int[10];
			for(int i = 0; i < s.length(); i++) {
				a[i] = Integer.parseInt(s.substring(i, i + 1));
				c[a[i]]++;
			}
			Set<Integer> set = new HashSet<Integer>();
			List<Integer> list = new ArrayList<Integer>();
			for(int i = 1; i <= 9; i++) {
				a[13] = i;
				System.arraycopy(c, 0, b, 0, 10);
				b[i]++;
				if(b[i] >= 5) continue;
				flag = false;
				dfs(0);
				if(flag) {
					list.add(i);
					set.add(i);
				}
			}
			for (int i = 1; i <= 9; i++) {
			    if (!set.contains(i)) {
			        a[13] = i;
			        int[] d = new int[10];
			        for (int j : a) {
			            d[j]++;
			        }
			        boolean flag1 = true;
			        for (int j = 0; j < 10; j++) {
			            if (d[j] != 0 && d[j] != 2) {
			                flag1 = false;
			                break;
			            } 
			        }
			        if (flag1){
			            list.add(i);
			        } 
			    }
			}
			if(list.size() == 0) {
				System.out.println(0);
			}else {
			    Collections.sort(list);
				for(int i = 0; i < list.size(); i++){
					System.out.println(list.get(i));
				}
			}
		}
		sc.close();
	}
	static boolean flag = false;
	static void dfs(int n) {
		if(n == 5) {
			flag = true;
			return;
		}
		if(flag) return;
		if(n == 0) {
			for(int i = 1; i <= 9; i++) {
				if(b[i] >= 2) {
					b[i] -= 2;
					dfs(n + 1);
					b[i] += 2;
				}
			}
		}
		for(int i = 1; i + 2 <= 9; i++) {
			if(b[i] >= 1 && b[i + 1] >= 1 && b[i + 2] >= 1) {
				b[i]--;
				b[i + 1]--;
				b[i + 2]--;
				dfs(n + 1);
				b[i]++;
				b[i + 1]++;
				b[i + 2]++;
			}
		}
		for(int i = 1; i <= 9; i++) {
			if(b[i] >= 3) {
				b[i] -= 3;
				dfs(n + 1);
				b[i] += 3;
			}
		}
	}
}
0