CF1743D.Problem with Random Tests

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given a string ss consisting of nn characters. Each character of ss is either 0 or 1.

A substring of ss is a contiguous subsequence of its characters.

You have to choose two substrings of ss (possibly intersecting, possibly the same, possibly non-intersecting — just any two substrings). After choosing them, you calculate the value of the chosen pair of substrings as follows:

  • let s1s_1 be the first substring, s2s_2 be the second chosen substring, and f(si)f(s_i) be the integer such that sis_i is its binary representation (for example, if sis_i is 11010, f(si)=26f(s_i) = 26);
  • the value is the bitwise OR of f(s1)f(s_1) and f(s2)f(s_2).

Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.

给你一个由 nn 个字符组成的字符串 ss,其中每个字符均为 0 或 1。

ss 的一个子串是指其字符的一个连续子序列。

你需要从 ss 中选出两个子串(允许相交、可以相同、也可以不相交——即任意两个子串均可)。选定后,你将按如下方式计算该子串对的值:

  • 设 s1s_1 为第一个子串,s2s_2 为第二个子串,f(si)f(s_i) 表示以 sis_i 作为二进制表示所对应的整数(例如,若 sis_i 为 11010,则 f(si)=26f(s_i) = 26);
  • 该值即为 f(s1)f(s_1) 与 f(s2)f(s_2) 的按位或(bitwise OR)结果。

请计算你能得到的最大可能值,并以不带前导零的二进制形式输出。

输入格式

The first line contains one integer nn — the number of characters in ss.

The second line contains ss itself, consisting of exactly nn characters 0 and/or 1.

All non-example tests in this problem are generated randomly: every character of ss is chosen independently of other characters; for each character, the probability of it being 1 is exactly 12\frac{1}{2}.

This problem has exactly 4040 tests. Tests from 11 to 33 are the examples; tests from 44 to 4040 are generated randomly. In tests from 44 to 1010, n=5n = 5; in tests from 1111 to 2020, n=1000n = 1000; in tests from 2121 to 4040, n=106n = 10^6.

Hacks are forbidden in this problem.

第一行包含一个整数 nn —— 字符串 ss 的字符个数。

第二行包含字符串 ss 本身,它恰好由 nn 个字符组成,每个字符为 0 或 1。

本题中所有非示例测试用例均为随机生成:字符串 ss 的每个字符独立选取;对每个字符而言,其为 1 的概率恰好为 12\frac{1}{2}。

本题共有 4040 个测试用例。其中第 11 至 33 个测试用例为示例;第 44 至 4040 个测试用例为随机生成。在第 44 至 1010 个测试用例中,n=5n = 5;在第 1111 至 2020 个测试用例中,n=1000n = 1000;在第 2121 至 4040 个测试用例中,n=106n = 10^6。

本题禁止使用 Hack。

输出格式

Print the maximum possible value you can get in binary representation without leading zeroes.

输出不带前导零的二进制表示下你能得到的最大可能值。

输入输出样例

  • 输入#1

    5
    11010

    输出#1

    11111
  • 输入#2

    7
    1110010

    输出#2

    1111110
  • 输入#3

    4
    0000

    输出#3

    0

说明/提示

In the first example, you can choose the substrings 11010 and 101. f(s1)=26f(s_1) = 26, f(s2)=5f(s_2) = 5, their bitwise OR is 3131, and the binary representation of 3131 is 11111.

In the second example, you can choose the substrings 1110010 and 11100.

在第一个例子中,你可以选择子字符串 11010 和 101。f(s1)=26f(s_1) = 26,f(s2)=5f(s_2) = 5,它们的按位或为 3131,而 3131 的二进制表示为 11111。

在第二个例子中,你可以选择子字符串 1110010 和 11100。

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

首页