結果

問題 No.675 ドットちゃんたち
ユーザー 👑 hos.lyric
提出日時 2019-05-21 10:29:10
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 2,820 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 120,996 KB
実行使用メモリ 42,116 KB
最終ジャッジ日時 2024-06-22 01:16:04
合計ジャッジ時間 3,794 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

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 SZ = 3;

long[][] mul(long[][] a, long[][] b) {
  auto c = new long[][](SZ, SZ);
  foreach (i; 0 .. SZ) foreach (k; 0 .. SZ) foreach (j; 0 .. SZ) {
    c[i][j] += a[i][k] * b[k][j];
  }
  return c;
}

int N;
long PX, PY;
int[] T;
long[] D;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      PX = readLong();
      PY = readLong();
      T = new int[N];
      D = new long[N];
      foreach (i; 0 .. N) {
        T[i] = readInt();
        if (T[i] == 1 || T[i] == 2) {
          D[i] = readLong();
        }
      }
      
      auto as = new long[][][](N, SZ, SZ);
      foreach (i; 0 .. N) {
        switch (T[i]) {
          case 1: {
            as[i][0][0] = 1;
            as[i][1][1] = 1;
            as[i][2][2] = 1;
            as[i][0][2] = D[i];
          } break;
          case 2: {
            as[i][0][0] = 1;
            as[i][1][1] = 1;
            as[i][2][2] = 1;
            as[i][1][2] = D[i];
          } break;
          case 3: {
            as[i][0][1] = 1;
            as[i][1][0] = -1;
            as[i][2][2] = 1;
          } break;
          default: assert(false);
        }
      }
      
      auto asProd = new long[][][N + 1];
      asProd[N] = new long[][](SZ, SZ);
      asProd[N][0][0] = 1;
      asProd[N][1][1] = 1;
      asProd[N][2][2] = 1;
      foreach_reverse (i; 0 .. N) {
        asProd[i] = mul(asProd[i + 1], as[i]);
      }
      
      foreach (i; 0 .. N) {
        const ansX = asProd[i][0][0] * PX + asProd[i][0][1] * PY + asProd[i][0][2];
        const ansY = asProd[i][1][0] * PX + asProd[i][1][1] * PY + asProd[i][1][2];
        writeln(ansX, " ", ansY);
      }
    }
  } catch (EOFException e) {
  }
}
0