結果
問題 | No.832 麻雀修行中 |
ユーザー | ks2m |
提出日時 | 2019-05-24 22:57:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 2,553 bytes |
コンパイル時間 | 3,563 ms |
コンパイル使用メモリ | 83,940 KB |
実行使用メモリ | 57,528 KB |
最終ジャッジ日時 | 2023-10-17 14:00:57 |
合計ジャッジ時間 | 8,894 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 127 ms
57,068 KB |
testcase_01 | AC | 129 ms
57,504 KB |
testcase_02 | AC | 128 ms
57,328 KB |
testcase_03 | AC | 127 ms
57,192 KB |
testcase_04 | AC | 129 ms
57,292 KB |
testcase_05 | AC | 127 ms
57,468 KB |
testcase_06 | AC | 127 ms
57,376 KB |
testcase_07 | AC | 128 ms
57,152 KB |
testcase_08 | AC | 128 ms
57,084 KB |
testcase_09 | AC | 128 ms
57,344 KB |
testcase_10 | AC | 127 ms
57,408 KB |
testcase_11 | AC | 126 ms
57,224 KB |
testcase_12 | AC | 127 ms
57,528 KB |
testcase_13 | AC | 127 ms
55,352 KB |
testcase_14 | AC | 128 ms
57,356 KB |
testcase_15 | AC | 131 ms
57,324 KB |
testcase_16 | AC | 131 ms
57,452 KB |
testcase_17 | AC | 134 ms
57,372 KB |
testcase_18 | AC | 132 ms
57,364 KB |
testcase_19 | AC | 129 ms
55,496 KB |
testcase_20 | AC | 129 ms
57,324 KB |
testcase_21 | AC | 130 ms
55,492 KB |
testcase_22 | AC | 134 ms
57,344 KB |
testcase_23 | AC | 130 ms
57,332 KB |
testcase_24 | AC | 130 ms
57,328 KB |
testcase_25 | AC | 129 ms
57,380 KB |
testcase_26 | AC | 134 ms
57,332 KB |
testcase_27 | AC | 131 ms
57,288 KB |
testcase_28 | AC | 132 ms
57,324 KB |
testcase_29 | AC | 132 ms
57,468 KB |
testcase_30 | AC | 132 ms
57,404 KB |
ソースコード
import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); String s = sc.next(); sc.close(); int[] cnt = new int[9]; for (int i = 0; i < s.length(); i++) { cnt[s.charAt(i) - '1']++; } TreeSet<Integer> ans = new TreeSet<Integer>(); // 七対子 int one = 0; int two = 0; int idx = 0; for (int i = 0; i < cnt.length; i++) { if (cnt[i] == 1) { one++; idx = i; } else if (cnt[i] == 2) { two++; } } if (one == 1 && two == 6) { ans.add(idx); } int[] work = new int[9]; for (int i = 0; i < 9; i++) { // 単騎 System.arraycopy(cnt, 0, work, 0, cnt.length); if (work[i] > 0) { work[i]--; if (threes(work) && cnt[i] < 4) { ans.add(i); } } // シャンポン System.arraycopy(cnt, 0, work, 0, cnt.length); if (work[i] > 1) { for (int j = i + 1; j < 9; j++) { System.arraycopy(cnt, 0, work, 0, cnt.length); if (work[j] > 1) { work[i] -= 2; work[j] -= 2; if (threes(work)) { if (cnt[i] < 4) ans.add(i); if (cnt[j] < 4) ans.add(j); } } } } // カンチャン System.arraycopy(cnt, 0, work, 0, cnt.length); if (i < 7 && work[i] > 0 && work[i + 2] > 0) { for (int j = 0; j < 9; j++) { System.arraycopy(cnt, 0, work, 0, cnt.length); work[i]--; work[i + 2]--; if (work[j] > 1) { work[j] -= 2; if (threes(work) && cnt[i + 1] < 4) { ans.add(i + 1); } } } } // 両面、ペンチャン System.arraycopy(cnt, 0, work, 0, cnt.length); if (i < 8 && work[i] > 0 && work[i + 1] > 0) { for (int j = 0; j < 9; j++) { System.arraycopy(cnt, 0, work, 0, cnt.length); work[i]--; work[i + 1]--; if (work[j] > 1) { work[j] -= 2; if (threes(work)) { if (i > 0 && cnt[i - 1] < 4) ans.add(i - 1); if (i < 7 && cnt[i + 2] < 4) ans.add(i + 2); } } } } } for (int i : ans) { System.out.println(i + 1); } } static boolean threes(int[] work) { boolean flg = true; for (int i = 0; i < 9; i++) { if (work[i] >= 3) { work[i] -= 3; } while (work[i] > 0) { work[i]--; if (i < 8 && work[i + 1] > 0) { work[i + 1]--; } else { flg = false; break; } if (i < 7 && work[i + 2] > 0) { work[i + 2]--; } else { flg = false; break; } } if (!flg) { break; } } return flg; } }