fork download
  1. #include<bits/stdc++.h>
  2. #define MOD 1000000007
  3. #define EPS 1e-15
  4. #define ll long long
  5. #define ld long double
  6. #define pb push_back
  7. #define mp make_pair
  8. #define endl '\n'
  9. #define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
  10. const ld PI=3.141592653589793238L;
  11. const ll N=100005;
  12. using namespace std;
  13.  
  14. ll n;
  15. ll r[1000],c[1000];
  16. ll C[1000][1000];
  17.  
  18. int main(){
  19. ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  20. // <<>>
  21.  
  22. cin>>n;
  23.  
  24. ll t[n][n];
  25. char ch;
  26. for(int i=0;i<n;++i) for(int j=0;j<n;++j) cin>>ch,t[i][j]=(ch=='B');
  27.  
  28. for(int i=0;i<n;++i) for(int j=0;j<n;++j) if(!t[i][j]) ++r[i],++c[j],++C[i][j];
  29.  
  30. vector<pair<ll,ll> >v1,v2;
  31. for(int i=0;i<n;++i) for(int j=0;j<n;++j){
  32. C[i][j]+=r[i]+c[j];
  33. if(C[i][j]&1) v1.pb(mp(i,j));
  34. else v2.pb(mp(i,j));
  35. }
  36.  
  37. if(v2.size()<v1.size()) swap(v1,v2);
  38.  
  39. cout<<v1.size()<<endl;
  40. for(int i=0;i<v1.size();++i) cout<<v1[i].first+1<<' '<<v1[i].second+1<<endl;
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 4400KB
stdin
4
WBWB
BWWW
WWBW
WBWB
stdout
2
2 3
3 1