結果

問題 No.3622 Perfect Matching of Crab
コンテスト
ユーザー 👑 Nachia
提出日時 2026-08-14 21:23:49
言語 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  
実行時間 60 ms / 2,000 ms
+ 409µs
コード長 1,066 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 473 ms
コンパイル使用メモリ 100,716 KB
実行使用メモリ 9,308 KB
最終ジャッジ日時 2026-08-14 21:23:54
合計ジャッジ時間 3,955 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
// disable assert
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }


void testcase(){
  ll N; cin >> N;
  V<ll> X, Y;
  ll d = 0;
  REP(i,N*2){
    ll x ,y; cin >> x >> y;
    char c; cin >> c;
    if(c == 'x'){
      Y.push_back(y);
      d++;
    } else {
      X.push_back(x);
      d--;
    }
  }
  if(d > 0) swap(X, Y);
  sort(X.begin(), X.end());
  ll cnt = 0;
  while(X.size()){
    if(X.size() >= 2 && X[X.size() - 2] == X.back()){
      cnt++;
      X.pop_back();
    }
    X.pop_back();
  }
  if(cnt * 2 >= abs(d)) cout << "Yes\n"; else cout << "No\n";
}

int main(){
  cin.tie(0)->sync_with_stdio(0);
  ll T; cin >> T; REP(t,T)
  testcase();
  return 0;
}
0