CF2264D.Dr. Agos's Dark Mode
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Someone has chopped up Dr. Agos's chickens. Furious, he turns to the one thing that still brings him comfort: his OLED screen. Today, he wants almost all of it black.
The screen has a single row of n pixels. Its pattern is represented by a binary string s; si=0 means that the i-th pixel is dark, and si=1 means that it is lit.
Dr. Agos finds a contiguous segment of pixels irritating if, when read from left to right as a binary integer, its value is divisible by 3. More precisely, the segment from position l to position r (1≤l≤r≤n) has value $$ \sum_{i=l}^{r} s_i \cdot 2^{r-i}. $$ Leading zeroes are allowed. A segment consisting only of dark pixels has value 0, which is also divisible by 3.
Let f(s) be the number of irritating segments. Segments with different pairs of endpoints (l,r) are counted separately, even if their pixel patterns are identical.
Dr. Agos wants a pattern with at most three lit pixels that minimizes f(s) among all binary strings of length n, including strings with more than three ones. Help him construct such a pattern.
We can show that an answer always exists.
有人把阿戈斯博士的鸡给剁了。他怒不可遏,转而投向唯一还能带给他慰藉的东西:他的 OLED 屏幕。今天,他希望屏幕几乎全部变黑。
该屏幕只有一行 n 个像素。其显示图案由一个二进制字符串 s 表示;其中 si=0 表示第 i 个像素为暗色,si=1 表示为亮色。
阿戈斯博士认为一段连续的像素是“令人烦躁的”,当且仅当将其从左到右视作一个二进制整数时,该整数的值能被 3 整除。更准确地说,位置从 l 到 r(1≤l≤r≤n)的这段像素所对应的值为
i=l∑rsi⋅2r−i.
允许前导零。仅包含暗色像素的段对应值为 0,而 0 也能被 3 整除。
令 f(s) 表示“令人烦躁的”子段的数量。具有不同端点对 (l,r) 的子段均被分别计数,即使它们的像素模式完全相同。
阿戈斯博士希望构造一个至多包含三个亮像素的图案,使得 f(s) 在所有长度为 n 的二进制字符串(包括含超过三个 1 的字符串)中达到最小。请帮助他构造这样的图案。
我们可以证明,这样的答案总是存在的。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line of each test case contains a single integer n (1≤n≤2⋅105) — the number of pixels in the row.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅有一行,包含一个整数 n(1≤n≤2⋅105)—— 表示该行中像素的数量。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print a binary string s of length n describing Dr. Agos's screen. It must contain at most three ones and minimize f(s) among all binary strings of length n.
If there are multiple solutions, print any of them.
对于每个测试用例,输出一个长度为 n 的二进制字符串 s,表示 Dr. Agos 的屏幕。该字符串中最多包含三个 1,且在所有长度为 n 的二进制字符串中使 f(s) 最小。
若存在多个满足条件的解,输出任意一个即可。
输入输出样例
输入#1
6 1 2 3 4 5 6
输出#1
1 11 101 0101 10101 010100
说明/提示
For n=1, Dr. Agos can light the only pixel, giving s=1. The only segment has value 1, so it is not irritating and f(s)=0.
For n=2, he can light both pixels, giving s=11. The whole row has binary value 3 and is irritating, while each individual pixel has value 1. Thus, f(s)=1. Every binary string of length 2 has at least one irritating segment, so this is optimal.
The displayed patterns are not necessarily unique.
当 n=1 时,Agos 博士可以点亮唯一的像素,得到 s=1。此时唯一的一段的值为 1,因此不令人烦躁,故 f(s)=0。
当 n=2 时,他可以点亮两个像素,得到 s=11。整行的二进制值为 3,是令人烦躁的;而每个单独的像素的值均为 1。因此,f(s)=1。所有长度为 2 的二进制字符串均至少含有一段令人烦躁的子段,因此该方案是最优的。
所展示的模式未必唯一。
输入解题思路,AI测评打分。不知道怎么写?