CF878A.Short Program

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.

In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.

Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.

佩佳学习了一门新的编程语言 CALPAS。该语言中的程序总是接收一个非负整数作为输入,并同样返回一个非负整数。

该语言中仅有三条指令:对当前整数执行按位与(AND)、按位或(OR)或按位异或(XOR)运算,运算符为给定的常数。一个程序可包含任意长度的上述操作序列,且每个操作所用的常数均可取 00 到 10231023 之间的任意整数。当程序运行时,所有操作将按给定顺序依次作用于输入参数,最终返回结果整数。

佩佳用该语言编写了一个程序,但发现其过长。请编写一个不超过 5 行的 CALPAS 程序,使其功能与佩佳的程序完全相同:即对所有从 00 到 10231023 的输入,均返回相同的输出整数。

输入格式

The first line contains an integer n (1 ≤ n ≤ 5·105) — the number of lines.

Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x__i 0 ≤ x__i ≤ 1023.

第一行包含一个整数 $ n (( 1 \leq n \leq 5 \cdot 10^5 $)—— 表示命令的行数。

接下来的 $ n $ 行每行包含一条命令。每条命令由一个表示运算符的字符(“&”、“|” 或 “^” 分别代表按位与、按位或、按位异或)以及一个常数 $ x_i (( 0 \leq x_i \leq 1023 $)组成。

输出格式

Output an integer k (0 ≤ k ≤ 5) — the length of your program.

Next k lines must contain commands in the same format as in the input.

输出一个整数 kk(0 ≤ k ≤ 50 \le k \le 5)——即你程序的长度。

接下来的 kk 行必须以与输入中相同的格式包含指令。

输入输出样例

  • 输入#1

    3
    | 3
    ^ 2
    | 1

    输出#1

    2
    | 3
    ^ 2
  • 输入#2

    3
    & 1
    & 3
    & 5

    输出#2

    1
    & 1
  • 输入#3

    3
    ^ 1
    ^ 2
    ^ 3

    输出#3

    0

说明/提示

You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation.

Second sample:

Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.

你可以在 https://en.wikipedia.org/wiki/Bitwise_operation 中了解位运算。

第二个样例:

设 x 为 Petya 程序的输入,则其输出为 ((x&1)&3)&5 = x&(1&3&5) = x&1。因此,这两个程序的输出始终相同。

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

首页