A15381 | Problem with Random Tests
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a string $s$ consisting of $n$ characters. Each character of $s$ is either 0 or 1.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (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 $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$ );
- the value is the bitwise OR of $f(s_1)$ and $f(s_2)$ .
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
A substring of $s$ is a contiguous subsequence of its characters.
You have to choose two substrings of $s$ (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 $s_1$ be the first substring, $s_2$ be the second chosen substring, and $f(s_i)$ be the integer such that $s_i$ is its binary representation (for example, if $s_i$ is 11010, $f(s_i) = 26$ );
- the value is the bitwise OR of $f(s_1)$ and $f(s_2)$ .
Calculate the maximum possible value you can get, and print it in binary representation without leading zeroes.
输入格式
The first line contains one integer $n$ — the number of characters in $s$ .
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$ .
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$ , $n = 5$ ; in tests from $11$ to $20$ , $n = 1000$ ; in tests from $21$ to $40$ , $n = 10^6$ .
Hacks are forbidden in this problem.
The second line contains $s$ itself, consisting of exactly $n$ characters 0 and/or 1.
All non-example tests in this problem are generated randomly: every character of $s$ is chosen independently of other characters; for each character, the probability of it being 1 is exactly $\frac{1}{2}$ .
This problem has exactly $40$ tests. Tests from $1$ to $3$ are the examples; tests from $4$ to $40$ are generated randomly. In tests from $4$ to $10$ , $n = 5$ ; in tests from $11$ to $20$ , $n = 1000$ ; in tests from $21$ to $40$ , $n = 10^6$ .
Hacks are forbidden in this problem.
输出格式
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(s_1) = 26$ , $f(s_2) = 5$ , their bitwise OR is $31$ , and the binary representation of $31$ is 11111.
In the second example, you can choose the substrings 1110010 and 11100.
In the second example, you can choose the substrings 1110010 and 11100.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted