#P9139. [THUPC 2023 初赛] 喵了个喵 II

    ID: 10218 远端评测题 4000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2023Special JudgeO2优化2-SAT可持久化线段树构造THUPC

[THUPC 2023 初赛] 喵了个喵 II

Background

Originally, this problem statement was related to "Meow Meow". But I heard some people thought the statement was too long, so let’s keep it short.

Problem Description

You are given a sequence of length 4n4n, where each number from 11 to nn appears exactly 44 times. Determine whether it is possible to split it into two identical subsequences of equal length.

Input Format

The first line contains a positive integer nn.

The second line contains 4n4n positive integers describing the sequence. It is guaranteed that each number from 11 to nn appears exactly 44 times.

Output Format

If it is impossible to split into two identical subsequences, output one line No.

Otherwise, output Yes on the first line. On the second line, output a 01 string of length 4n4n. The ii-th character indicates which subsequence the ii-th number of the original sequence is assigned to. You must ensure that the two subsequences you obtain are exactly identical.

2
1 1 2 1 2 2 1 2
Yes
10000111

Hint

Sample Explanation 1

Both subsequences are (1,2,1,2)(1,2,1,2).

Subtasks

Constraints: 1n5×1041\le n \le 5\times10^4.

It is guaranteed that each number from 11 to nn appears exactly 44 times in the sequence.

Scoring

The first line of your output must match the standard answer. If it is Yes, any valid splitting is accepted.

Source

From the preliminary round of the 2023 Tsinghua University Student Algorithm and Programming Contest and Collegiate Invitational (THUPC2023).

Resources such as editorials can be found at https://github.com/THUSAAC/THUPC2023-Pre.

By E.Space: Since the testdata was too weak during the contest, the testdata for this problem has been strengthened.

Translated by ChatGPT 5