8977: link with Checksum

内存限制:256 MB 时间限制:1 S
题面:传统 评测方式:Special Judge 上传者:
提交:0 通过:0

题目描述

link has invented an algorithm called CRC-link. In order to calculate CRC-link checksum of a datagram, let's assume the input byte array as DDD and the CRC-link polynomial as PPP (P=0x04C11DB7P=\text{0x04C11DB7}P=0x04C11DB7), and follow the three steps below.

  1. Treat each byte of the input byte array DDD as an 8-bit binary number. Append 32 zero bits to the end of DDD, creating an initial remainder RRR.
  2. Repeat the following step for NNN times, where NNN is the number of bits in DDD.
    • If the most significant bit of RRR is 1, shift RRR one bit to the left, then perform an XOR operation: XOR the most significant 32 bits of RRR with the CRC-link polynomial PPP.
    • Otherwise, just shift RRR one bit to the left.
  3. The most significant 32 bits of RRR is the CRC-link checksum of DDD.

For example, if DDD = {0x01, 0x02}, the CRC-link checksum can be calculated by:
00000001 00000010 00000000 00000000 00000000 00000000
(shift left for 7 bits)
10000001 00000000 00000000 00000000 00000000 00000000
(shift left for 1 bit, then xor P)
00000110 11000001 00011101 10110111 00000000 00000000
(shift left for 5 bits)
11011000 00100011 10110110 11100000 00000000 00000000
(shift left for 1 bit, then xor P)
10110100 10000110 01110000 01110111 00000000 00000000
(shift left for 1 bit, then xor P)
01101101 11001101 11111101 01011001 00000000 00000000
(shift left for 1 bit)
11011011 10011011 11111010 10110010 00000000 00000000
(since we have shifted 16 bits in total, the left 32 bits above is what we need)
Please note that CRC-link may be slightly different from CRC32.

For a datagram consisting of three parts: a header (n1n_1n1 bytes), a checksum (444 bytes), and a footer (n2n_2n2 bytes), the header and footer are given, while the checksum needs to be determined by you. You should choose a checksum that matches the CRC-link calculation result of the entire datagram. Formally, you should make sure CRC-link(concat(header,YourAnswer,footer)) equals to YourAnswer.

You may refer the example explanation for better understanding of how to check your answer.

输入格式

The first line contains two integers, n1n_1n1 and n2n_2n2 (1≤n1,n2≤1051 \le n_1, n_2 \le 10^51n1,n2105), representing the lengths of the header and footer, respectively.
The second line contains n1n_1n1 integers, where the iii-th integer aia_iai (0≤ai<280 \le a_i < 2^80ai<28) represents the value of the iii-th byte in the header.
The third line contains n2n_2n2 integers, where the iii-th integer bib_ibi (0≤bi<280 \le b_i < 2^80bi<28) represents the value of the iii-th byte in the footer.

输出格式

If a feasible checksum exists, output the checksum value (in decimal). Otherwise, output `-1'.
If multiple feasible solutions exist, you can output any one of them.

输入样例 复制

1 2
114
51 4

输出样例 复制

456567105

数据范围与提示

In the first example, when outputting `456567105', the answer is correct because CRC-link(72 1B 36 A9 41 33 04) equals to `456567105'.

分类标签