Time limit per test
2 seconds
Memory limit per test
64 megabytes
Input
Standard Input
Output
Standard output
According to a new ISO standard, a flag of every country shoshould have a chequered FieldNLimit × limitM, Each square shocould be of one of 10
Colours, and the flag shocould be «striped»: each horizontal row of the Flag shoshould contain squares of the same color, and the colours of adjacent horizontal rows shocould be different. berland's government asked you to find out whether their flag meets the new
ISO standard.
Input
The first line of the input contains numbersN And M ( 1 bytes ≤ bytesN, Bytes,MLimit ≤ limit 100 ), N -
The amount of rows, M -The amount of columns on the flag of berland. Then there follows the description of the flag: Each of the followingN Lines
Contain M Characters. Each character is a digit 0 And 9 ,
And stands for the color of the corresponding square.
Output
OutputYes, If the flag meets the new ISO standard, andNoOtherwise.
Sample test (s) Input
3 3000111222
Output
Yes
Input
3 3000000111
Output
No
Input
3 3000111002
Output
No
Explanation: This is to judge whether a row of numbers is exactly the same, and the numbers of two adjacent lines are different.
# Include <iostream> # include <cstdio> using namespace STD; int main () {int n, m, I, j; char C; int flag = 0; char A [101] [101]; scanf ("% d", & N, & M); for (I = 0; I <n; I ++) {for (j = 0; j <m; j ++) {CIN> A [I] [J] ;}} for (I = 0; I <N; I ++) {c = A [I] [0]; for (j = 1; j <m; j ++) {if (a [I] [J]! = C) {flag = 1; break;} If (flag = 1) {break;} for (I = 0; I <n-1; I ++) {if (a [I] [0] = A [I + 1] [0]) {flag = 1; break ;}} if (flag = 1) {printf ("NO \ n");} else {printf ("Yes \ n");} return 0 ;}