CF1698G.Long Binary String

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a binary string tt of length 1010010^{100}, and initally all of its bits are 0\texttt{0}. You are given a binary string ss, and perform the following operation some times:

  • Select some substring of tt, and replace it with its XOR with ss.†^\dagger

After several operations, the string tt has exactly two bits 1\texttt{1}; that is, there are exactly two distinct indices pp and qq such that the pp-th and qq-th bits of tt are 1\texttt{1}, and the rest of the bits are 0\texttt{0}.

Find the lexicographically largest‡^\ddagger string tt satisfying these constraints, or report that no such string exists.

†^\dagger Formally, choose an index ii such that 0≤i≤10100−∣s∣0 \leq i \leq 10^{100}-|s|. For all 1≤j≤∣s∣1 \leq j \leq |s|, if sj=1s_j = \texttt{1}, then toggle ti+jt_{i+j}. That is, if ti+j=0t_{i+j}=\texttt{0}, set ti+j=1t_{i+j}=\texttt{1}. Otherwise if ti+j=1t_{i+j}=\texttt{1}, set ti+j=0t_{i+j}=\texttt{0}.

‡^\ddagger A binary string aa is lexicographically larger than a binary string bb of the same length if in the first position where aa and bb differ, the string aa has a bit 1\texttt{1} and the corresponding bit in bb is 0\texttt{0}.

存在一个长度为 1010010^{100} 的二进制字符串 tt,初始时其所有比特均为 0\texttt{0}。你被给定一个二进制字符串 ss,并可执行如下操作若干次:

  • 选取 tt 的某个子串,并将其与 ss 进行按位异或(XOR)运算后替换原位置。†^\dagger

经过若干次操作后,字符串 tt 恰好包含两个比特 1\texttt{1};即存在两个互异的下标 pp 和 qq,使得 tt 的第 pp 位和第 qq 位为 1\texttt{1},其余所有比特均为 0\texttt{0}。

在满足上述约束的所有可能字符串 tt 中,找出字典序最大者‡^\ddagger;若不存在这样的字符串,则报告无解。

†^\dagger 形式化定义:选择一个下标 ii,满足 0≤i≤10100−∣s∣0 \leq i \leq 10^{100}-|s|。对每个 1≤j≤∣s∣1 \leq j \leq |s|,若 sj=1s_j = \texttt{1},则翻转 ti+jt_{i+j} 的值:即若 ti+j=0t_{i+j}=\texttt{0},则设为 1\texttt{1};若 ti+j=1t_{i+j}=\texttt{1},则设为 0\texttt{0}。

‡^\ddagger 对于两个等长的二进制字符串 aa 和 bb,若在 aa 与 bb 首次出现差异的位置上,aa 的对应比特为 1\texttt{1} 而 bb 的对应比特为 0\texttt{0},则称 aa 的字典序大于 bb。

输入格式

The only line of each test contains a single binary string ss (1≤∣s∣≤351 \leq |s| \leq 35).

每个测试用例仅包含一行,其中为一个二进制字符串 ss(1≤∣s∣≤351 \leq |s| \leq 35)。

输出格式

If no string tt exists as described in the statement, output -1. Otherwise, output the integers pp and qq (1≤p<q≤101001 \leq p \lt q \leq 10^{100}) such that the pp-th and qq-th bits of the lexicographically maximal tt are 1\texttt{1}.

如果不存在满足题面描述的字符串 tt,则输出 −1-1。否则,输出整数 pp 和 qq(1≤p<q≤101001 \leq p \lt q \leq 10^{100}),使得字典序最大的 tt 的第 pp 位和第 qq 位均为 1\texttt{1}。

输入输出样例

  • 输入#1

    1

    输出#1

    1 2
  • 输入#2

    001

    输出#2

    3 4
  • 输入#3

    1111

    输出#3

    1 5
  • 输入#4

    00000

    输出#4

    -1
  • 输入#5

    00000111110000011111000001111101010

    输出#5

    6 37452687

说明/提示

In the first test, you can perform the following operations. $$\texttt{00000}\ldots \to \color{red}{\texttt{1}}\texttt{0000}\ldots \to \texttt{1}\color{red}{\texttt{1}}\texttt{000}\ldots$$

In the second test, you can perform the following operations. $$\texttt{00000}\ldots \to \color{red}{\texttt{001}}\texttt{00}\ldots \to \texttt{0}\color{red}{\texttt{011}}\texttt{0}\ldots$$

In the third test, you can perform the following operations. $$\texttt{00000}\ldots \to \color{red}{\texttt{1111}}\texttt{0}\ldots \to \texttt{1}\color{red}{\texttt{0001}}\ldots$$

It can be proven that these strings tt are the lexicographically largest ones.

In the fourth test, you can't make a single bit 1\texttt{1}, so it is impossible.

在第一个测试用例中,你可以执行以下操作:

00000…→10000…→11000…\texttt{00000}\ldots \to \color{red}{\texttt{1}}\texttt{0000}\ldots \to \texttt{1}\color{red}{\texttt{1}}\texttt{000}\ldots

在第二个测试用例中,你可以执行以下操作:

00000…→00100…→00110…\texttt{00000}\ldots \to \color{red}{\texttt{001}}\texttt{00}\ldots \to \texttt{0}\color{red}{\texttt{011}}\texttt{0}\ldots

在第三个测试用例中,你可以执行以下操作:

00000…→11110…→10001…\texttt{00000}\ldots \to \color{red}{\texttt{1111}}\texttt{0}\ldots \to \texttt{1}\color{red}{\texttt{0001}}\ldots

可以证明,这些字符串 tt 是字典序最大的。

在第四个测试用例中,你无法将任意一位变为 1\texttt{1},因此不可能实现。

输入解题思路,AI测评打分。不知道怎么写?

首页