結果

問題 No.3622 Perfect Matching of Crab
コンテスト
ユーザー alcea
提出日時 2026-08-14 21:32:03
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 81 ms / 2,000 ms
+ 769µs
コード長 904 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 12,387 ms
コンパイル使用メモリ 203,440 KB
実行使用メモリ 9,388 KB
最終ジャッジ日時 2026-08-14 21:32:19
合計ジャッジ時間 4,498 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use proconio::input;
use std::collections::HashSet;

fn solve() {
  input! {
    n: usize,
    xyc: [(i32, i32, char); 2 * n],
  }
  let mut cntx = 0;
  let mut stx = HashSet::new();
  let mut cnty = 0;
  let mut sty = HashSet::new();
  for (x, y, c) in xyc {
    match c {
      'x' => {
        cntx += 1;
        if stx.contains(&y) {
          stx.remove(&y);
        }
        else {
          stx.insert(y);
        }
      },
      'y' => {
        cnty += 1;
        if sty.contains(&x) {
          sty.remove(&x);
        }
        else {
          sty.insert(x);
        }
      },
      _ => unreachable!(),
    }
  }
  let ans = if stx.len() < sty.len() {
    sty.len() - stx.len() <= cntx - stx.len()
  }
  else {
    stx.len() - sty.len() <= cnty - sty.len()
  };
  println!("{}", if ans {"Yes"} else {"No"});
}

fn main() {
  input! {
    t: usize,
  }
  for _ in 0..t {
    solve();
  }
}
0