-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy path16A. Flag.cpp
62 lines (51 loc) · 835 Bytes
/
16A. Flag.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
problem name:16A. Flag
problem link:http://codeforces.com/contest/16/problem/A
status:accepted
author:sakr
**/
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
string arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int countr=0;
int countc=0;
for(int i=0;i<n;i++){
int couentsmilar=count(arr[i].begin(),arr[i].end(),arr[i][0]);
if(couentsmilar ==m)++countr ;
if(n>1)
if(!i){
if(arr[i][0]!=arr[i+1][0]) ++countc;
}
else if(i==n-1){
if(arr[i][0]!=arr[i-1][0]){
++countc;
}
}
else {
if(arr[i][0]!=arr[i+1][0]&&arr[i][0]!=arr[i-1][0])
++countc;
}
}
if(n>1)
if(countc==countr&&countr==n)
cout<<"YES\n";
else{
cout<<"NO\n";
}
else {
if(countr)
cout<<"YES\n";
else{
cout<<"NO\n";
}
}
return 0;
}