QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 32 MB 満点: 100

#11863. 斐波那契数列求和

統計

斐波那契数列是一个整数序列,定义如下:$\text{Fib}_0=1, \text{Fib}_1=1, \text{Fib}_i=\text{Fib}_{i-2}+\text{Fib}_{i-1}$(对于 $i \ge 2$)。该序列的前几项为:(1, 1, 2, 3, 5, 8, …)。

伟大的计算机科学家 Byteazar 正在构建一台不同寻常的计算机,其中的数字用斐波那契系统表示,即位串 $(b_1, b_2, \dots, b_n)$ 表示数字 $b_1 \cdot \text{Fib}_1 + b_2 \cdot \text{Fib}_2 + \dots + b_n \cdot \text{Fib}_n$。(注意,我们不使用 $\text{Fib}_0$。)不幸的是,这种表示法是不唯一的,即同一个数字可以有不同的表示形式。例如,数字 42 可以写成:(0, 0, 0, 0, 1, 0, 0, 1)、(0, 0, 0, 0, 1, 1, 1, 0) 或 (1, 1, 0, 1, 0, 1, 1)。正因如此,Byteazar 将自己限制在仅使用满足以下条件的表示法:

  • 如果 $n > 1$,则 $b_n=1$,即数字的表示不包含前导零。
  • 如果 $b_i=1$,则 $b_{i+1}=0$(对于 $i=1, \dots, n-1$),即数字的表示不包含两个(或更多)连续的 1。

计算机的构建过程比 Byteazar 预想的要困难得多。他在实现加法时遇到了困难。请帮帮他!

编写一个程序,完成以下任务:

  • 从标准输入读取两个正整数的表示形式,
  • 计算它们的和,并将该和的表示形式写入标准输出。

输入格式

输入包含两个正整数 $x$ 和 $y$ 的斐波那契表示(满足上述条件),分别位于第一行和第二行。每种表示形式均为一系列由空格分隔的非负整数。行中的第一个数字表示表示形式的长度 $n$,$1 \le n \le 1\,000\,000$。随后是 $n$ 个 0 和/或 1。

输出格式

在输出的唯一一行中,你的程序应写入和 $x+y$ 的斐波那契表示(满足上述条件)。该表示形式应为一系列由空格分隔的非负整数,格式与输入部分描述的一致。行中的第一个数字表示表示形式的长度 $n$,$1 \le n \le 1\,000\,000$。随后是 $n$ 个 0 和/或 1。

样例

输入 1

4 0 1 0 1
5 0 1 0 0 1

输出 1

6 1 0 1 0 0 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.