結果
問題 | No.832 麻雀修行中 |
ユーザー | Grenache |
提出日時 | 2019-05-24 22:01:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 221 ms / 2,000 ms |
コード長 | 3,306 bytes |
コンパイル時間 | 3,944 ms |
コンパイル使用メモリ | 85,568 KB |
実行使用メモリ | 58,256 KB |
最終ジャッジ日時 | 2024-09-17 10:41:44 |
合計ジャッジ時間 | 10,118 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 176 ms
57,196 KB |
testcase_01 | AC | 173 ms
56,828 KB |
testcase_02 | AC | 171 ms
56,884 KB |
testcase_03 | AC | 207 ms
58,104 KB |
testcase_04 | AC | 193 ms
57,172 KB |
testcase_05 | AC | 192 ms
56,948 KB |
testcase_06 | AC | 190 ms
56,812 KB |
testcase_07 | AC | 198 ms
56,852 KB |
testcase_08 | AC | 163 ms
57,092 KB |
testcase_09 | AC | 171 ms
56,652 KB |
testcase_10 | AC | 203 ms
57,236 KB |
testcase_11 | AC | 203 ms
57,388 KB |
testcase_12 | AC | 221 ms
58,256 KB |
testcase_13 | AC | 153 ms
56,952 KB |
testcase_14 | AC | 205 ms
57,256 KB |
testcase_15 | AC | 185 ms
57,212 KB |
testcase_16 | AC | 183 ms
56,860 KB |
testcase_17 | AC | 180 ms
57,064 KB |
testcase_18 | AC | 182 ms
56,952 KB |
testcase_19 | AC | 206 ms
57,992 KB |
testcase_20 | AC | 167 ms
56,780 KB |
testcase_21 | AC | 200 ms
57,216 KB |
testcase_22 | AC | 179 ms
56,732 KB |
testcase_23 | AC | 181 ms
57,096 KB |
testcase_24 | AC | 178 ms
56,716 KB |
testcase_25 | AC | 177 ms
57,036 KB |
testcase_26 | AC | 173 ms
56,744 KB |
testcase_27 | AC | 175 ms
57,224 KB |
testcase_28 | AC | 154 ms
57,160 KB |
testcase_29 | AC | 176 ms
57,064 KB |
testcase_30 | AC | 177 ms
57,256 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder832 { private static Scanner sc; private static Printer pr; private static void solve() { char[] s = sc.next().toCharArray(); int[] cnt = new int[9]; for (char c : s) { cnt[c - '1']++; } for (int i = 0; i < 9; i++) { if (cnt[i] == 4) { continue; } int[] tmp = Arrays.copyOf(cnt, cnt.length); tmp[i]++; if (isOK(tmp)) { pr.println(i + 1); } } } private static boolean isOK(int[] cnt) { // chitoi boolean chitoi = true; for (int e : cnt) { if (e != 2 && e != 0) { chitoi = false; break; } } if (chitoi) { return true; } for (int a = 0; a < 9; a++) { if (cnt[a] < 2) { continue; } int[] tmp = Arrays.copyOf(cnt, cnt.length); tmp[a] -= 2; if (isOK2(tmp)) { return true; } } return false; } private static boolean isOK2(int[] cnt) { Deque<List<Integer>> st = new ArrayDeque<>(); st.push(new ArrayList<>()); while (!st.isEmpty()) { List<Integer> list = st.pop(); if (list.size() == 4) { if (isOK3(list, cnt)) { return true; } } else { int s; if (list.size() == 0) { s = 0; } else { s = list.get(list.size() - 1) + 1; } for (int i = s; i < men.length; i++) { if (isOK3(list, cnt)) { List<Integer> tmp = new ArrayList<>(list); tmp.add(i); st.push(tmp); } } } } return false; } private static boolean isOK3(List<Integer> list, int[] cnt) { int[] tmp = new int[9]; for (int e : list) { for (int i = 0; i < 9; i++) { tmp[i] += men[e][i]; } } for (int i = 0; i < 9; i++) { if (tmp[i] > cnt[i]) { return false; } } return true; } private static int[][] men = { {3, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 3, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 3, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 3, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 3, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 3, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 3, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 3, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 3}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, }; // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }