結果

問題 No.3622 Perfect Matching of Crab
コンテスト
ユーザー tnakao0123
提出日時 2026-08-17 15:26:53
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 66 ms / 2,000 ms
+ 759µs
コード長 1,199 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 217 ms
コンパイル使用メモリ 56,496 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-17 15:26:58
合計ジャッジ時間 4,350 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3622.cc:  No.3622 Perfect Matching of Crab - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_N2 = MAX_N * 2;

/* typedef */

/* global variables */

int xs[MAX_N2], ys[MAX_N2];

/* subroutines */

/* main */

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

  while (tn--) {
    int n;
    scanf("%d", &n);
    int n2 = n * 2, xn = 0, yn = 0, hc = 0, vc = 0;
    for (int i = 0; i < n2; i++) {
      int xi, yi;
      char cs[4];
      scanf("%d%d%s", &xi, &yi, cs);
      if (cs[0] == 'x') hc++, ys[yn++] = yi;
      else vc++, xs[xn++] = xi;
    }

    if (hc > vc) {
      sort(ys, ys + yn);
      int sum = 0;
      for (int i = 0; i < yn;) {
	int j = i;
	while (i < yn && ys[j] == ys[i]) i++;
	sum += (i - j) / 2;
      }
      if (vc + sum >= n) puts("Yes");
      else puts("No");
    }
    else if (hc < vc) {
      sort(xs, xs + xn);
      int sum = 0;
      for (int i = 0; i < xn;) {
	int j = i;
	while (i < xn && xs[j] == xs[i]) i++;
	sum += (i - j) / 2;
      }
      if (hc + sum >= n) puts("Yes");
      else puts("No");
    }
    else
      puts("Yes");
  }

  return 0;
}

0