結果

問題 No.3622 Perfect Matching of Crab
コンテスト
ユーザー LyricalMaestro
提出日時 2026-08-18 01:50:45
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 348 ms / 2,000 ms
+ 895µs
コード長 1,059 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 247 ms
コンパイル使用メモリ 95,980 KB
実行使用メモリ 153,500 KB
最終ジャッジ日時 2026-08-18 01:50:53
合計ジャッジ時間 6,874 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# https://yukicoder.me/problems/no/3622
 
def solve(N, xyc):
    x_map = {}
    y_map = {}
    for x, y, c in xyc:
        if c == "x":
            if y not in x_map:
                x_map[y] = 0
            x_map[y] += 1
        else:
            if x not in y_map:
                y_map[x] = 0
            y_map[x] += 1

    x_low = 0
    x_high = 0
    for value in x_map.values():
        if value % 2 == 1:
            x_low += 1
        x_high += value
    y_low = 0
    y_high = 0
    for value in y_map.values():
        if value % 2 == 1:
            y_low += 1
        y_high += value

    if y_high < x_low or x_high < y_low:
        return "No"
    else:
        return "Yes"


def main():
    T = int(input())
    answers = []
    for _ in range(T):
        N = int(input())
        xyc = []
        for _ in range(2 * N):
            x, y, c = input().split()
            xyc.append((int(x), int(y), c))
        ans = solve(N, xyc)
        answers.append(ans)

    for ans in answers:
        print(ans)




if __name__ == "__main__":
    main()
0