結果

問題 No.675 ドットちゃんたち
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-05-21 10:29:10
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 2,820 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 106,896 KB
実行使用メモリ 42,336 KB
最終ジャッジ日時 2023-09-04 01:09:32
合計ジャッジ時間 4,016 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 197 ms
42,280 KB
testcase_06 AC 213 ms
42,336 KB
testcase_07 AC 190 ms
36,440 KB
testcase_08 AC 207 ms
41,788 KB
testcase_09 AC 212 ms
40,908 KB
testcase_10 AC 212 ms
41,640 KB
testcase_11 AC 215 ms
42,168 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 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