CF1743G.Antifibonacci Cut

NOI/NOI+/CTSC

通过率:0%

时间限制:12.00s

内存限制:4MB

AC君温馨提醒

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

题目描述

Note that the memory limit is unusual.

Let's define the sequence of Fibonacci strings as follows: f0f_0 is 0, f1f_1 is 1, fif_i is fi−1+fi−2f_{i-1} + f_{i-2} for i>1i \gt 1 (++ denotes the concatenation of two strings). So, for example, f2f_2 is 10, f3f_3 is 101, f4f_4 is 10110.

For a given string ss, let's define g(s)g(s) as the number of ways to cut it into several (any number, possibly even just one) strings such that none of these strings are Fibonacci strings. For example, if ss is 10110101, g(s)=3g(s) = 3 since there are three ways to cut it:

  • 101101 ++ 01;
  • 1011 ++ 0101;
  • 1011 ++ 01 ++ 01.

You are given a sequence of strings s1,s2,…,sns_1, s_2, \dots, s_n. Calculate g(s1),g(s1+s2),…,g(s1+s2+…+sn)g(s_1), g(s_1 + s_2), \dots, g(s_1 + s_2 + \ldots + s_n). Since these values can be huge, print them modulo 998244353998244353.

注意内存限制较为特殊。

我们定义斐波那契字符串序列如下:f0f_0 为字符串 0,f1f_1 为字符串 1,对 i>1i > 1,fi=fi−1+fi−2f_i = f_{i-1} + f_{i-2}(其中 ++ 表示两个字符串的拼接)。例如,f2=10f_2 = \texttt{10},f3=101f_3 = \texttt{101},f4=10110f_4 = \texttt{10110}。

对给定字符串 ss,定义 g(s)g(s) 为将 ss 切分为若干个(任意个数,甚至可仅为一个)子串的方式数目,使得这些子串中无一是斐波那契字符串。例如,若 s=10110101s = \texttt{10110101},则 g(s)=3g(s) = 3,因为存在以下三种切分方式:

  • 101101 ++ 01;
  • 1011 ++ 0101;
  • 1011 ++ 01 ++ 01。

现给出一串字符串 s1,s2,…,sns_1, s_2, \dots, s_n。请计算 g(s1),  g(s1+s2),  …,  g(s1+s2+…+sn)g(s_1),\; g(s_1 + s_2),\; \dots,\; g(s_1 + s_2 + \ldots + s_n)。由于结果可能极大,请对 998244353998244353 取模后输出。

输入格式

The first line of the input contains one integer nn (1≤n≤3⋅1031 \le n \le 3 \cdot 10^3).

Then, nn lines follow. The ii-th line contains the string sis_i (1≤∣si∣≤1031 \le |s_i| \le 10^3), consisting of characters 0 and/or 1.

输入的第一行包含一个整数 nn(1≤n≤3⋅1031 \le n \le 3 \cdot 10^3)。

接下来有 nn 行。第 ii 行包含字符串 sis_i(1≤∣si∣≤1031 \le |s_i| \le 10^3),该字符串仅由字符 0 和/或 1 组成。

输出格式

Print nn integers, where the ii-th integer is g(s1+s2+…+si) mod 998244353g(s_1 + s_2 + \ldots + s_i) \bmod 998244353.

输出 nn 个整数,其中第 ii 个整数为 g(s1+s2+…+si) mod 998244353g(s_1 + s_2 + \ldots + s_i) \bmod 998244353。

输入输出样例

  • 输入#1

    1
    10110101

    输出#1

    3
  • 输入#2

    3
    1111
    1
    0

    输出#2

    2
    3
    3
  • 输入#3

    6
    10110101
    100100001110
    0000001100010001
    1111
    1001010100101010101001
    000100000010101111

    输出#3

    3
    561
    1466229
    9887505
    972227653
    52128355

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

首页