Codeforces Beta Round #16 (Div. 2 Only)
http://codeforces.com/contest/16
水题
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 500005 7 typedef long long ll; 8 /*#ifndef ONLINE_JUDGE 9 freopen("1.txt","r",stdin); 10 #endif */ 11 12 int n,m; 13 string str[105]; 14 15 int main(){ 16 #ifndef ONLINE_JUDGE 17 // freopen("1.txt","r",stdin); 18 #endif 19 cin>>n>>m; 20 int flag=0; 21 map<int,int>mp; 22 for(int i=0;i<n;i++) cin>>str[i]; 23 for(int i=1;i<n;i++){ 24 if(str[i][0]==str[i-1][0]) flag=1; 25 } 26 if(!flag){ 27 if(m==1){ 28 cout<<"YES"<<endl; 29 } 30 else{ 31 for(int k=0;k<n;k++){ 32 for(int i=1;i<m;i++){ 33 if(str[k][i]!=str[k][i-1]) flag=1; 34 } 35 } 36 if(flag) cout<<"NO"<<endl; 37 else cout<<"YES"<<endl; 38 } 39 } 40 else{ 41 cout<<"NO"<<endl; 42 } 43 }