結果

問題 No.606 カラフルタイル
ユーザー ふっぴーふっぴー
提出日時 2017-12-06 13:55:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 2,469 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 174,120 KB
実行使用メモリ 7,232 KB
最終ジャッジ日時 2023-08-19 09:39:49
合計ジャッジ時間 4,805 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 9 ms
4,504 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 10 ms
4,616 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 41 ms
4,500 KB
testcase_17 AC 194 ms
6,120 KB
testcase_18 AC 52 ms
5,468 KB
testcase_19 AC 51 ms
5,412 KB
testcase_20 AC 208 ms
6,928 KB
testcase_21 AC 69 ms
6,204 KB
testcase_22 AC 69 ms
6,152 KB
testcase_23 AC 89 ms
6,424 KB
testcase_24 AC 162 ms
6,616 KB
testcase_25 AC 192 ms
6,944 KB
testcase_26 AC 196 ms
7,232 KB
testcase_27 AC 196 ms
7,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vector<char> a(q);
  vl b(q), c(q);
  int i, j;
  vector<pii> tate(n, pii(-1, 0)), yoko(n, pii(-1, 0));
  for (i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i];
    b[i]--; c[i]--;
    if (a[i] == 'R') {
      yoko[b[i]].first = i;
    }
    else {
      tate[b[i]].first = i;
    }
  }
  sort(yoko.begin(), yoko.end());
  sort(tate.begin(), tate.end());
  int yokoi = n-1, tatei = n-1;
  while (yokoi >= 0 || tatei >= 0) {
    if (yokoi < 0) {
      tate[tatei].second = (n - 1 - yokoi);
      tatei--;
    }
    else if (tatei < 0) {
      yoko[yokoi].second = (n - 1 - tatei);
      yokoi--;
    }
    else if (yoko[yokoi].first < 0 && tate[tatei].first < 0) {
      yoko[yokoi].second = (n - 1 - tatei);
      yokoi--;
    }
    else {
      if (yoko[yokoi].first > tate[tatei].first) {
	yoko[yokoi].second = (n - 1) - tatei;
	yokoi--;
      }
      else {
	tate[tatei].second = (n - 1) - yokoi;
	tatei--;
      }
    }
  }
  /*
  for (i = 0; i < n; i++) {
    cout << yoko[i].first << " " << yoko[i].second << endl;
  }
  cout << endl;
  for (i = 0; i < n; i++) {
    cout << tate[i].first << " " << tate[i].second << endl;
  }
  cout << endl;
  */
  vl color(k);
  for (i = 0; i < n; i++) {
    if (yoko[i].first < 0) {
      color[0] += n - yoko[i].second;
    }
    else {
      color[c[yoko[i].first]] += n - yoko[i].second;
    }
  }
  for (i = 0; i < n; i++) {
    if (tate[i].first < 0) {
      color[0] += n - tate[i].second;
    }
    else {
      color[c[tate[i].first]] += n - tate[i].second;
    }
  }
  for (i = 0; i < k; i++) {
    cout << color[i] << endl;
  }
  return 0;
}
  
/*
3 4 6
C 1 2
C 2 3
R 2 1
C 3 4
R 3 3
C 2 1

1 5 2
R 1 4
R 1 4

100000 2 1
R 12345 2
*/
0