結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー tnakao0123tnakao0123
提出日時 2023-06-04 15:24:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,635 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 62,840 KB
実行使用メモリ 6,320 KB
最終ジャッジ日時 2023-08-28 08:15:47
合計ジャッジ時間 28,997 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 51 ms
4,376 KB
testcase_03 AC 54 ms
4,376 KB
testcase_04 AC 53 ms
4,376 KB
testcase_05 AC 53 ms
4,380 KB
testcase_06 AC 53 ms
4,376 KB
testcase_07 AC 48 ms
4,376 KB
testcase_08 AC 56 ms
4,376 KB
testcase_09 AC 56 ms
4,376 KB
testcase_10 AC 55 ms
4,380 KB
testcase_11 AC 63 ms
4,752 KB
testcase_12 AC 54 ms
4,480 KB
testcase_13 AC 73 ms
4,940 KB
testcase_14 AC 57 ms
4,400 KB
testcase_15 AC 51 ms
4,376 KB
testcase_16 AC 63 ms
4,376 KB
testcase_17 AC 57 ms
4,376 KB
testcase_18 AC 72 ms
6,292 KB
testcase_19 AC 74 ms
5,992 KB
testcase_20 AC 73 ms
6,208 KB
testcase_21 AC 72 ms
6,148 KB
testcase_22 AC 73 ms
6,236 KB
testcase_23 AC 72 ms
6,284 KB
testcase_24 AC 73 ms
6,076 KB
testcase_25 AC 73 ms
6,148 KB
testcase_26 AC 73 ms
6,316 KB
testcase_27 AC 72 ms
6,224 KB
testcase_28 AC 74 ms
6,192 KB
testcase_29 AC 74 ms
6,240 KB
testcase_30 AC 73 ms
6,004 KB
testcase_31 AC 73 ms
6,284 KB
testcase_32 AC 73 ms
6,320 KB
testcase_33 AC 73 ms
6,276 KB
testcase_34 AC 73 ms
6,136 KB
testcase_35 AC 73 ms
6,024 KB
testcase_36 AC 73 ms
6,132 KB
testcase_37 AC 73 ms
6,228 KB
testcase_38 AC 68 ms
4,380 KB
testcase_39 AC 95 ms
4,376 KB
testcase_40 AC 64 ms
4,376 KB
testcase_41 AC 64 ms
4,376 KB
testcase_42 AC 73 ms
5,828 KB
testcase_43 AC 72 ms
5,872 KB
testcase_44 AC 73 ms
6,268 KB
testcase_45 AC 73 ms
6,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:79:15: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   79 |     for (auto [c, e]: ans)
      |               ^

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2307.cc:  No.2307 [Cherry 5 th Tune *] Cool 46 - yukicoder
 */

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

/* constant */

const int MAX_N = 200000;
const int MAX_M = 200000;

enum { R, B };
const char css[2][8] = {"Red", "Blue"};

/* typedef */

typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

int as[MAX_N], bs[MAX_M];

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%d", as + i);
    for (int i = 0; i < m; i++) scanf("%d", bs + i);
    sort(as, as + n);
    sort(bs, bs + m);

    qi rv, bv, ev;
    int ai = 0, bi = 0;
    while (ai < n && bi < m) {
      if (as[ai] < bs[bi]) rv.push(as[ai++]);
      else if (as[ai] > bs[bi]) bv.push(bs[bi++]);
      else ev.push(as[ai++]), bi++;
    }
    while (ai < n) rv.push(as[ai++]);
    while (bi < m) bv.push(bs[bi++]);

    if (! rv.empty() && ! bv.empty() && ev.empty()) {
      puts("No"); continue;
    }

    vpii ans;
    int c = (! rv.empty()) ? R : B;
    while (! rv.empty() || ! bv.empty() || ! ev.empty()) {
      while (c == R && ! rv.empty())
	ans.push_back({R, rv.front()}), rv.pop();
      while (c == B && ! bv.empty())
	ans.push_back({B, bv.front()}), bv.pop();

      if (! ev.empty()) {
	int e = ev.front(); ev.pop();
	ans.push_back({c, e});
	c ^= 1;
	ans.push_back({c, e});
      }
    }

    puts("Yes");
    for (auto [c, e]: ans)
      printf("%s %d\n", css[c], e);
  }
  return 0;
}
0