Byte Me!
Time limit2sMemory limit512 MB
Given N data bytes and a parity byte, find the parity type, the one data byte with wrong popcount parity, and the flipped bit position.
- Level
Medium4 of 10
- Topics
- Bit manipulation, Implementation, Array
- Solved
- No attempts yet
Problem
Parity is one way to check data transmission for errors. Transmission is not error proof, so parity tells you whether the data was corrupted on the way.
Under even parity every byte contains an even number of 1 characters. Under odd parity every byte contains an odd number of 1 characters.
In this problem you look for a single corrupted bit. The last byte of the input is not part of the transmitted data. It is a parity byte: bit of the parity byte is the parity bit for bit of the data bytes, and it uses the same parity as the data bytes. For every position , counting bit of the data bytes together with bit of the parity byte matches the parity in use.
Exactly one bit of one data byte was flipped. That byte is the only data byte whose number of 1 characters disagrees with the parity in use, and the flipped position is the only position whose column disagrees with it. Report the parity in use, the broken byte, and the broken bit.
Input
The first line contains an integer (), the number of data bytes. Each of the next lines contains one byte as 8 characters separated by single spaces. Each character is 0 or 1.
One more line follows in the same format, the parity byte. Its bit is the parity bit for position of the preceding lines and uses the same parity as the data bytes. The number of 1 characters inside the parity byte itself need not match that parity.
Output
Print three lines.
- Line 1:
Evenif the bytes that are not broken use even parity,Oddif they use odd parity. - Line 2:
Byte B is broken, whereBis the number of the broken byte. The first data byte is number 1. - Line 3:
Bit C is broken, whereCis the position of the broken bit inside its byte. The leftmost position is number 1.