結果

問題 No.675 ドットちゃんたち
ユーザー te-shte-sh
提出日時 2018-04-16 14:53:45
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 2,188 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 148,880 KB
実行使用メモリ 25,684 KB
最終ジャッジ日時 2023-09-03 19:33:23
合計ジャッジ時間 3,997 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 165 ms
25,644 KB
testcase_06 AC 172 ms
25,664 KB
testcase_07 AC 169 ms
25,304 KB
testcase_08 AC 169 ms
25,564 KB
testcase_09 AC 172 ms
25,684 KB
testcase_10 AC 172 ms
25,564 KB
testcase_11 AC 177 ms
25,660 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(66): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
Main.d(73): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.
Main.d(80): Deprecation: usage of the `body` keyword is deprecated. Use `do` instead.

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}

void main()
{
  int n, px, py; readV(n, px, py);
  auto c = new Matrix!int[](n);
  foreach (i; 0..n) {
    auto rd = readln.splitter, ct = rd.front.to!int; rd.popFront;
    switch (ct) {
    case 1:
      c[i] = Matrix!int([[1, 0, rd.front.to!int], [0, 1, 0], [0, 0, 1]]);
      break;
    case 2:
      c[i] = Matrix!int([[1, 0, 0], [0, 1, rd.front.to!int], [0, 0, 1]]);
      break;
    case 3:
      c[i] = Matrix!int([[0, 1, 0], [-1, 0, 0], [0, 0, 1]]);
      break;
    default:
      assert(0);
    }
  }

  auto m = Matrix!int.unit(3), x = new int[](n), y = new int[](n);
  foreach_reverse (i; 0..n) {
    m = m * c[i];
    x[i] = m[0][0]*px + m[0][1]*py + m[0][2];
    y[i] = m[1][0]*px + m[1][1]*py + m[1][2];
  }

  foreach (xi, yi; lockstep(x, y))
    writeln(xi, " ", yi);
}

struct Matrix(T)
{
  size_t r, c;
  T[][] a;
  alias a this;

  static ref auto unit(size_t n)
  {
    auto r = Matrix!T(n, n);
    foreach (i; 0..n) r[i][i] = 1;
    return r;
  }

  this(size_t r, size_t c)
  {
    this.r = r; this.c = c;
    a = new T[][](r, c);
    static if (T.init != 0) foreach (i; 0..r) a[i][] = 0;
  }

  this(T[][] b)
  {
    r = b.length;
    c = b[0].length;
    a = b;
  }

  ref auto dup() { auto x = Matrix!T(r, c); foreach (i; 0..r) x[i][] = a[i][]; return x; }

  ref auto opBinary(string op)(Matrix!T b) if (op == "+" || op == "-") in { assert(r == b.r && c == b.c); } body
  {
    auto x = Matrix!T(r, c);
    foreach (i; 0..r) foreach (j; 0..c) x[i][j] = mixin("a[i][j]"~op~"b[i][j]");
    return x;
  }

  ref auto opBinary(string op: "*")(Matrix!T b) in { assert(c == b.r); } body
  {
    auto x = Matrix!T(r, b.c);
    foreach (i; 0..r) foreach (j; 0..b.c) foreach (k; 0..c) x[i][j] += a[i][k]*b[k][j];
    return x;
  }

  ref auto opBinary(string op: "*")(T[] b) in { assert(c == b.length); } body
  {
    auto x = new T[](r);
    static if (T.init != 0) x[] = 0;
    foreach (i; 0..r) foreach (j; 0..c) x[i] += a[i][j]*b[j];
    return x;
  }
}
0