#P10872. [COTS 2022] 移位 Maliand

    ID: 12343 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心2022Special JudgeO2优化位运算构造COCI(克罗地亚)Ad-hoc

[COTS 2022] 移位 Maliand

Background

Translated from Izborne Pripreme 2022 (Croatian IOI/CEOI Team Selection) D1T2. 2s,0.5G\texttt{2s,0.5G}.

SPJ link.

Problem Description

Given non-negative integers N,K,LN,K,L, construct two 0101 sequences S,TS,T such that:

  • The lengths of SS and TT are NN.
  • SS contains exactly KK ones, and TT contains exactly LL ones.
  • f(S,T)f(S,T) is the minimum among all possible f(S,T)f(S,T).

Define f(S,T)f(S,T) as follows: after applying any cyclic shifts to SS and TT, take the maximum value of i=1NSiandTi\sum_{i=1}^{N} S_i\operatorname{and} T_i, where and\mathrm{and} denotes the bitwise AND operation.

You need to construct SS and TT.

Input Format

One line with three integers N,K,LN,K,L.

Output Format

The first line contains an integer FF, which is the minimum value of f(S,T)f(S,T).

The next two lines describe the sequences SS and TT, respectively. There is no need to output spaces between adjacent elements.

If there are multiple solutions, output any one of them.

6 4 3
2
011011
101010
5 2 0
0
01001
00000
10 7 6
5
1101100111
1110001101

Hint

For 100%100\% of the testdata, it is guaranteed that 1N5×1051\le N\le 5\times 10^5 and 0K,LN0\le K,L\le N.

Subtask ID Score Constraints
11 55 1N131\le N\le 13
22 5050 1N50001\le N\le 5\, 000
33 4545 No additional constraints

Scoring:

  • If you answer FF correctly, you can get 20%20\% of the score.
  • On this basis, if your S,TS,T satisfy the conditions, you will get the remaining 80%80\% of the score.
  • If you only plan to answer the first part, you still need to output any two 0101 sequences satisfying conditions 1 and 2, otherwise you are not guaranteed to get any score.

Translated by ChatGPT 5