結果

問題 No.606 カラフルタイル
ユーザー te-sh
提出日時 2017-12-06 11:41:55
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 106,324 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 22:49:05
合計ジャッジ時間 2,595 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], k = rd[1], q = rd[2];

  struct Query { char a; int b, c; }
  auto queries = new Query[](q);
  foreach (i; 0..q) {
    auto rd2 = readln.splitter;
    auto a = rd2.front[0]; rd2.popFront();
    auto b = rd2.front.to!int-1; rd2.popFront();
    auto c = rd2.front.to!int-1;
    queries[i] = Query(a, b, c);
  }

  auto cnt = new long[](k), vr = new bool[](n), vc = new bool[](n);
  auto nr = n, nc = n;
  foreach_reverse (query; queries) {
    switch (query.a) {
    case 'R':
      if (vr[query.b]) continue;
      vr[query.b] = true;
      cnt[query.c] += nc;
      --nr;
      break;
    case 'C':
      if (vc[query.b]) continue;
      vc[query.b] = true;
      cnt[query.c] += nr;
      --nc;
      break;
    default:
      assert(0);
    }
  }

  cnt[0] = n.to!long ^^ 2 - cnt[1..$].sum;
  cnt.each!writeln;
}
0