Submission #20881177


Source Code Expand

Copy
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, 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 M = 7;

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const S = readToken();
      const X = readToken();
      
      auto vals = new int[N];
      vals[N - 1] = 1;
      foreach_reverse (i; 0 .. N - 1) {
        vals[i] = (vals[i + 1] * 10) % M;
      }
      
      auto dp = new char[][](N + 1, M);
      dp[N][0] = 'T';
      dp[N][1 .. M] = 'A';
      foreach_reverse (i; 0 .. N) {
        foreach (u; 0 .. M) {
          if (X[i] == 'T') {
            dp[i][u] = 'A';
          } else {
            dp[i][u] = 'T';
          }
          foreach (s; 0 .. 2) {
            const v = (u + vals[i] * (S[i] - '0') * s) % M;
            if (X[i] == 'T') {
              if (dp[i + 1][v] == 'T') {
                dp[i][u] = 'T';
              }
            } else {
              if (dp[i + 1][v] == 'A') {
                dp[i][u] = 'A';
              }
            }
          }
        }
      }
      debug {
        writeln("dp = ", dp);
      }
      writeln((dp[0][0] == 'T') ? "Takahashi" : "Aoki");
    }
  } catch (EOFException e) {
  }
}

Submission Info

Submission Time
Task E - Lucky 7 Battle
User hos_lyric
Language D (LDC 1.20.1)
Score 500
Code Size 2319 Byte
Status AC
Exec Time 39 ms
Memory 7140 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 37
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_31.txt, random_32.txt, random_33.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
hand_01.txt AC 8 ms 3224 KB
hand_02.txt AC 3 ms 3280 KB
hand_03.txt AC 4 ms 3228 KB
hand_04.txt AC 4 ms 3288 KB
random_01.txt AC 31 ms 7008 KB
random_02.txt AC 31 ms 6660 KB
random_03.txt AC 35 ms 7036 KB
random_04.txt AC 28 ms 6296 KB
random_05.txt AC 28 ms 7116 KB
random_06.txt AC 23 ms 5136 KB
random_11.txt AC 32 ms 6944 KB
random_12.txt AC 30 ms 6024 KB
random_13.txt AC 36 ms 7016 KB
random_14.txt AC 27 ms 6288 KB
random_15.txt AC 36 ms 7104 KB
random_16.txt AC 26 ms 5188 KB
random_17.txt AC 37 ms 7036 KB
random_18.txt AC 23 ms 5184 KB
random_19.txt AC 33 ms 7044 KB
random_20.txt AC 27 ms 5948 KB
random_21.txt AC 38 ms 7140 KB
random_22.txt AC 37 ms 6736 KB
random_23.txt AC 39 ms 7044 KB
random_24.txt AC 34 ms 6236 KB
random_25.txt AC 36 ms 7100 KB
random_26.txt AC 28 ms 5048 KB
random_31.txt AC 25 ms 6988 KB
random_32.txt AC 28 ms 7084 KB
random_33.txt AC 30 ms 7048 KB
random_41.txt AC 27 ms 7008 KB
random_42.txt AC 34 ms 7092 KB
random_43.txt AC 31 ms 6980 KB
random_44.txt AC 26 ms 7040 KB
sample_01.txt AC 4 ms 3112 KB
sample_02.txt AC 4 ms 3332 KB
sample_03.txt AC 4 ms 3228 KB
sample_04.txt AC 3 ms 3296 KB