結果

問題 No.832 麻雀修行中
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-05-24 21:44:00
言語 D
(dmd 2.105.2)
結果
WA  
実行時間 -
コード長 2,633 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 111,036 KB
実行使用メモリ 4,880 KB
最終ジャッジ日時 2023-09-04 01:19:00
合計ジャッジ時間 3,663 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
4,376 KB
testcase_01 AC 54 ms
4,376 KB
testcase_02 AC 46 ms
4,376 KB
testcase_03 AC 52 ms
4,376 KB
testcase_04 AC 54 ms
4,376 KB
testcase_05 AC 47 ms
4,880 KB
testcase_06 AC 46 ms
4,376 KB
testcase_07 AC 54 ms
4,380 KB
testcase_08 AC 52 ms
4,376 KB
testcase_09 AC 52 ms
4,380 KB
testcase_10 AC 49 ms
4,380 KB
testcase_11 AC 50 ms
4,376 KB
testcase_12 AC 54 ms
4,376 KB
testcase_13 AC 50 ms
4,380 KB
testcase_14 AC 53 ms
4,376 KB
testcase_15 AC 57 ms
4,376 KB
testcase_16 AC 49 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 51 ms
4,380 KB
testcase_19 AC 54 ms
4,380 KB
testcase_20 AC 48 ms
4,376 KB
testcase_21 AC 54 ms
4,376 KB
testcase_22 AC 47 ms
4,380 KB
testcase_23 AC 50 ms
4,376 KB
testcase_24 AC 48 ms
4,380 KB
testcase_25 AC 54 ms
4,376 KB
testcase_26 AC 46 ms
4,380 KB
testcase_27 AC 53 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 50 ms
4,376 KB
testcase_30 AC 58 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {
  }
}
0