結果

問題 No.3622 Perfect Matching of Crab
コンテスト
ユーザー msksknkn
提出日時 2026-08-15 20:25:28
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 1,646 ms / 2,000 ms
+ 973µs
コード長 1,085 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,492 ms
コンパイル使用メモリ 87,644 KB
実行使用メモリ 84,832 KB
最終ジャッジ日時 2026-08-15 20:25:53
合計ジャッジ時間 19,742 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

package no3622_perfect_matching_crab;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		while(t > 0) {
			t--;
			int n = sc.nextInt();
			HashMap<Integer,Integer> x = new HashMap<>();
			HashMap<Integer,Integer> y = new HashMap<>();
			int xc = 0;
			int yc = 0;
			for(int i = 0;i < 2 * n;i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				char c = sc.next().charAt(0);
				if(c == 'x') {
					xc++;
					if(!x.containsKey(b)) {
						x.put(b, 0);
					}x.put(b, x.get(b) + 1);
				}else {
					yc++;
					if(!y.containsKey(a)) {
						y.put(a, 0);
					}y.put(a,y.get(a) + 1);
				}
			}int xsub = xc - yc;
			int ysub = yc - xc;
			int makeX = 0;
			int makeY = 0;
			for(int s:x.keySet()) {
				makeX += x.get(s)/2 * 2;
			}for(int s:y.keySet()) {
				makeY += y.get(s)/2 * 2;
			}sb.append(xsub <= makeX && ysub <= makeY ? "Yes\n":"No\n");
		}System.out.print(sb);
	}

}
0