結果
| 問題 | 
                            No.832 麻雀修行中
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-05-24 21:44:00 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,633 bytes | 
| コンパイル時間 | 994 ms | 
| コンパイル使用メモリ | 124,596 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-22 01:22:54 | 
| 合計ジャッジ時間 | 3,114 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 WA * 1 | 
| other | AC * 24 WA * 1 | 
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }
bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }
int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }
enum N = 14;
bool check7(in int[] as) {
  auto bs = as.dup;
  bs.sort;
  for (int i = 0; i < N; i += 2) {
    if (bs[i] != bs[i + 1]) {
      return false;
    }
  }
  return true;
}
bool check(in int[] as) {
  debug {
    writeln("check ", as);
    stdout.flush;
  }
  assert(cast(int)(as.length) == N);
  if (check7(as)) {
    return true;
  }
  auto ok3 = new bool[1 << N];
  foreach (i; 0 .. N) foreach (j; i + 1 .. N) foreach (k; j + 1 .. N) {
    int[] bs = [as[i], as[j], as[k]];
    bs.sort;
    if (bs[0] == bs[1] && bs[0] == bs[2]) {
      ok3[1 << i | 1 << j | 1 << k] = true;
    }
    if (bs[0] + 1 == bs[1] && bs[0] + 2 == bs[2]) {
      ok3[1 << i | 1 << j | 1 << k] = true;
    }
  }
  auto dp = new bool[1 << 14];
  foreach (i; 0 .. N) foreach (j; i + 1 .. N) {
    if (as[i] == as[j]) {
      dp[1 << i | 1 << j] = true;
    }
  }
  foreach (s; 0 .. 1 << 14) {
    for (int t = s; t; --t &= s) {
      if (ok3[t] && dp[s ^ t]) {
        dp[s] = true;
      }
    }
  }
  return dp[(1 << 14) - 1];
}
void main() {
  try {
    for (; ; ) {
      const S = readToken();
      
      int[] as;
      auto cnt = new int[9];
      foreach (c; S) {
        const a = c - '1';
        as ~= a;
        ++cnt[a];
      }
      
      int[] ans;
      foreach (a; 0 .. 9) {
        if (cnt[a] < 4) {
          if (check(as ~ a)) {
            ans ~= a;
          }
        }
      }
      foreach (a; ans) {
        writeln(1 + a);
      }
    }
  } catch (EOFException e) {
  }
}