結果

問題 No.675 ドットちゃんたち
ユーザー ikdikd
提出日時 2018-04-16 18:47:05
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 1,324 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 142,092 KB
実行使用メモリ 39,440 KB
最終ジャッジ日時 2023-09-03 19:36:16
合計ジャッジ時間 4,522 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 234 ms
39,348 KB
testcase_06 AC 265 ms
39,260 KB
testcase_07 AC 239 ms
38,912 KB
testcase_08 AC 248 ms
39,344 KB
testcase_09 AC 263 ms
39,316 KB
testcase_10 AC 261 ms
39,436 KB
testcase_11 AC 262 ms
39,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  long px, py; rd(n, px, py);
  int m=3;
  auto mats=new long[][][](n, m, m);
  foreach(i; 0..n){
    auto args=readln.split.to!(int[]);
    if(args[0]==1){
      mats[i][0][0]=mats[i][1][1]=mats[i][2][2]=1;
      mats[i][0][2]=args[1];
    }else if(args[0]==2){
      mats[i][0][0]=mats[i][1][1]=mats[i][2][2]=1;
      mats[i][1][2]=args[1];
    }else if(args[0]==3){
      mats[i][0][1]=1;
      mats[i][1][0]=-1;
      mats[i][2][2]=1;
    }
  }
  auto T=new long[][](m, m);
  T[0][0]=T[1][1]=T[2][2]=1;
  long[] v=[px, py, 1L];
  struct Point{
    long x, y;
    string toString(){
      return x.to!(string)~" "~y.to!(string);
    }
  }
  auto points=new Point[](n);
  foreach_reverse(idx, mat; mats){
    auto U=new long[][](m, m);
    foreach(i; 0..m)foreach(j; 0..m){
      long tmp=0;
      foreach(k; 0..m) tmp+=T[i][k]*mat[k][j];
      U[i][j]=tmp;
    }
    T.swap(U);
    long qx=0, qy=0;
    foreach(k; 0..m){
      qx+=T[0][k]*v[k];
      qy+=T[1][k]*v[k];
    }
    points[idx]=Point(qx, qy);
    // writeln(qx, " ", qy);
  }
  writefln("%(%s\n%)", points);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}
0