結果

問題 No.2042 RGB Caps
ユーザー tnakao0123tnakao0123
提出日時 2022-08-20 14:14:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 49,228 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 13:01:29
合計ジャッジ時間 3,486 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2042.cc:  No.2042 RGB Caps - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const char ccs[] = "RGB";

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int cmap[128], cs[3];
pii acs[MAX_N];
char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  for (int i = 0; ccs[i]; i++) cmap[ccs[i]] = i;

  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 0; i < k; i++) {
    int ai;
    char cis[4];
    scanf("%d%s", &ai, cis);
    acs[i] = pii(ai, cmap[cis[0]]);
  }
  sort(acs, acs + k);

  fill(cs, cs + 3, 0);
  int l = 0;
  for (int i = 0; i < k; i++) {
    int ai = acs[i].first, ci = acs[i].second;
    int mi = (ai + 2) / 3;
    while (l < ai && cs[ci] < mi) s[l++] = ccs[ci], cs[ci]++;

    if (cs[ci] < cs[(ci + 1) % 3] || cs[ci] < cs[(ci + 2) % 3]) {
      puts("-1"); return 0;
    }
  }

  while (l < n) s[l++] = 'R';
  puts(s);
  return 0;
}
0