結果

問題 No.2702 Nand Nor Matrix
ユーザー 👑 hos.lyric
提出日時 2024-03-30 00:54:23
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 3,011 bytes
コンパイル時間 1,132 ms
コンパイル使用メモリ 117,180 KB
実行使用メモリ 21,264 KB
最終ジャッジ日時 2024-09-30 17:19:27
合計ジャッジ時間 14,656 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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; }

string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; }

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)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt;
      auto A = new int[N];
      auto B = new int[N];
      foreach (y; 0 .. N) A[y] = readInt;
      foreach (x; 1 .. N) B[x] = readInt;
      B[0] = A[0];
      const Q = readInt;
      auto T = new long[Q];
      auto X = new int[Q];
      auto Y = new int[Q];
      foreach (q; 0 .. Q) {
        T[q] = readLong;
        X[q] = readInt - 1;
        Y[q] = readInt - 1;
      }
      
      int m, n;
      for (n = 1; n < N && A[n] == (n & 1); ++n) {}
      for (m = 1; m < N && B[m] == (m & 1); ++m) {}
      
      int solve(long t, int x, int y) {
        if (x == 0) return A[y];
        if (y == 0) return B[x];
        int ret;
        if (x < m && y < n && x + y <= t + 1) {
          ret = (x + y + t) & 1;
        }
        ret ^= (t & 1);
        return ret;
      }
      
      debug {
        const limT = 2 * N + 5;
        auto brt = new int[][][](limT, N, N);
        foreach (y; 0 .. N) brt[0][0][y] = A[y];
        foreach (x; 1 .. N) brt[0][x][0] = B[x];
        foreach (t; 0 .. limT - 1) {
          foreach (x; 0 .. N) foreach (y; 0 .. N) {
            brt[t + 1][x][y] = (x == 0 || y == 0) ? brt[t][x][y] : ((brt[t][x - 1][y] + brt[t][x][y - 1] + brt[t][x][y] <= 1) ? 1 : 0);
          }
        }
        foreach (t; 0 .. limT) {
          writeln("t = ", t);
          foreach (x; 0 .. N) {
            foreach (y; 0 .. N) write(brt[t][x][y] ^ (t & 1));
            writeln;
          }
          foreach (x; 0 .. N) foreach (y; 0 .. N) {
            const slv = solve(t, x, y);
            assert(brt[t][x][y] == slv, format("%s %s %s: %s %s", t, x, y, brt[t][x][y], slv));
          }
        }
      }
      
      foreach (q; 0 .. Q) {
        writeln(solve(T[q], X[q], Y[q]));
      }
    }
  } catch (EOFException e) {
  }
}
0