Problem:
H - 植林
問題文
とある大学の魔法学部の生徒であるK君は広大な屋敷に住んでいる．
  屋敷の裏には林が広がっていたが，所々木が生えていない箇所があった．
  このままでは屋敷からの見た目が悪いと感じたので，K君は木が生えていない箇所に木を植えることに決めた．
  魔法使いの卵であるK君は使い魔を召喚することが出来るので，植林の作業を使い魔にやらせようと考えた．
林は
H × W
個のセルを持つ長方形領域とみなすことが出来る．
  各セルは木が1本生えているか1本も生えていないかのどちらかである．
  K君はこの
H × W
個のセルのどれか 1 つを指定し，そこに使い魔を召喚する．
  しかしK君はまだ未熟者なので，魔力を調節することが出来ず，使い魔を召喚するときは必ず 5 匹召喚してしまう．
  さらに悪いことに，K君が召喚する使い魔はひねくれもので，訪れたセルに木が生えていない場合はそこに木を植えるが，訪れたセルに既に木が生えている場合はそのセルの木を消してしまう．
  召喚された使い魔のうちの 4 匹は，指定されたセルを始点として東西南北に散らばり1直線上を進み，1つ1つセルを訪れていく．これらの使い魔は林の外に出ると消える．
  残りの使い魔は指定されたセルのみを訪問し，その後直ちに消える．
より正確に言えば，K君がセル
(i, j)
に使い魔を召喚すると，
i
行目か或いは
j
列目にある
H+W-1
個のセルに対し，
  木が生えていなければ木が植えられ，木が生えていれば木が消されるという操作が行われる．
召喚には多くの魔力を必要とするので，出来るだけ少ない召喚回数で林を木で覆いつくしたい．
  K君はどのセルに使い魔を召喚すれば最小の召喚回数で林を木で覆いつくすことが出来るだろうか．
入力形式
入力は以下の形式で与えられる．
H
W
a
1,1
...
a
1,W
...
a
H,1
...
a
H,W
a
i,j
が
1
ならセル
(i,j)
に木が生えていることを意味し,
0
なら生えていないことを意味する．
出力形式
もし林を木で覆いつくすことが不可能なら，1行に
Impossible
を出力せよ．
そうでなければ，召喚回数を最小にするような召喚手順を以下の形式で
H
行に出力せよ．
b
1,1
... b
1,W
...
b
H,1
... b
H,W
b
i,j
は
0
もしくは
1
でなければならず,
1
ならセル
(i,j)
に使い魔を召喚する事を意味し，
0
なら召喚しない事を意味する．
2回同じ場所に使い魔を召喚しても意味が無いことに注意せよ．召喚回数を最小にするような召喚手順が複数ある場合はどれを出力しても良い．
制約
2 ≤ H，W ≤ 1000
H，W
は偶数
a
i,j
∈ {0, 1}
この問題の判定には，3 点分のテストケースのグループが設定されている． このグループに含まれるテストケースは上記の制約に加えて下記の制約も満たす．
H × W ≤ 20
入出力例
入力例 1
4 4
0 0 0 1
0 1 1 0
0 1 1 0
1 0 0 0
出力例 1
1 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1
セル
(1,1)
とセル
(4,4)
に使い魔を召喚することで林を木で覆いつくすことが出来る．
Writer: 田村和範
Tester: 花田裕一朗

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w));
    vector<ll> ch(h), cw(w);
    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            cin >> a[i][j];
            ch[i] += (1 - a[i][j]);
            cw[j] += (1 - a[i][j]);
        }
    }
    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            ll C = ch[i] + cw[j];
            if (a[i][j] == 0)
            {
                C -= 1;
            }
            cout << C % 2;
            if (j != w - 1)
            {
                cout << " ";
            }
        }
        cout << endl;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 11264
final_rank: 12

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<int> a(h), b(w);
    vector<vector<int>> c(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int w;
            cin >> w;
            if (!w) {
                c[i][j] = 1;
                a[i] ^= 1;
                b[j] ^= 1;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (j) cout << " ";
            cout << (a[i] ^ b[j] ^ c[i][j]);
        }
        cout << "\n";
    }
}
accuracy: 1
time_ms: 70
memory_kb: 7032
final_rank: 2

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-8, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 998244353 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  if(x == 0) return 0;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
template<typename T> 
struct BIT{
  int N;
  std::vector<T> node;
  BIT(){}
  BIT(int n){
    N = n;
    node.resize(N+10);
  }
  void build(int n) {
    N = n;
    node.resize(N+10);
  }
  /* a: 1-indexed */
  void add(int a, T x){
    for(int i=a; i<(int)node.size(); i += i & -i) node[i] += x;
  }

  /* [1, a] */
  T sum(int a){
    T res = 0;
    for(int x=a; x>0; x -= x & -x) res += node[x];
    return res;
  }

  /* [l, r] */
  T rangesum(int l, int r){
    return sum(r) - sum(l-1);
  }

  /* 
    a1+a2+...+aw >= valとなるような最小のwを返す
    @verify https://codeforces.com/contest/992/problem/E
  */
  int lower_bound(T val) {
    if(val < 0) return 0;

    int res = 0;
    int n = 1; 
    while (n < N) n *= 2;

    T tv=0;
    for (int k = n; k > 0; k /= 2) {
      if(res + k < N && node[res + k] < val){
        val -= node[res+k];
        res += k;
      }
    }
    return res+1; 
  }
};
struct UnionFind{
  std::vector<int> par;
  std::vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) std::swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
struct RollingHash{

    using ull = unsigned long long;
    const ull mod = (1ULL << 61) - 1;
    const ull MASK30 = (1ULL << 30) - 1;
    const ull MASK31 = (1ULL << 31) - 1;

    const ull MASK61 = mod;

    ull base;
    int n;
    vector<ull> hash, pow;

    RollingHash(const string &s)
    {
        random_device rnd;
        mt19937_64 mt(rnd());
        base = 1001;
        
        n = (int)s.size();
        hash.assign(n+1, 0);
        pow.assign(n+1, 1);
        
        for(int i=0; i<n; i++){
            hash[i+1] = calc_mod(mul(hash[i], base) + s[i]);
            pow[i+1] = calc_mod(mul(pow[i], base));
        }
    }

    ull calc_mod(ull x){
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if(res >= mod) res -= mod;
        return res;
    }

    ull mul(ull a, ull b){
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & MASK30;
        return calc_mod(au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    //[l,r)のハッシュ値
    inline ull get(int l, int r){
        ull res = calc_mod(hash[r] + mod*3-mul(hash[l], pow[r-l]));
        return res;
    }
    //string tのハッシュ値
    inline ull get(string t){
        ull res = 0;
        for(int i=0; i<t.size(); i++){
            res = calc_mod(mul(res, base)+t[i]);
        }
        return res;
    }
    //string s中のtの数をカウント
    inline int count(string t) {
        if(t.size() > n) return 0;
        auto hs = get(t);
        int res = 0;
        for(int i=0; i<n-t.size()+1; i++){
            if(get(i, i+t.size()) == hs) res++; 
        }
        return res;
    }

    /* 
        concat 
        @verify https://codeforces.com/problemset/problem/514/C
    */
    inline ull concat(ull h1, ull h2, int h2len){
      return calc_mod(h2 + mul(h1, pow[h2len]));
    }

    // LCPを求める S[a:] T[b:]
    inline int LCP(int a, int b){
        int len = min((int)hash.size()-a, (int)hash.size()-b);
        
        int lb = -1, ub = len;
        while(ub-lb>1){
            int mid = (lb+ub)/2;

            if(get(a, a+mid) == get(b, b+mid)) lb = mid;
            else ub = mid;
        }
        return lb;
    }
};

int main() {  
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  
  int h, w; cin >> h >> w;
  vector<int> cnt(h), cnt2(w);
  vector<vector<int>> a(h, vector<int>(w));
  REP(i,h) {
    REP(j,w) {
      int c; cin >> c;
      a[i][j] = c;
      if(c == 0) {
        cnt[i]++;
        cnt2[j]++;
      }
    }
  }
  REP(i,h) {
    REP(j,w) {
      if(j) cout << " ";
      if((cnt[i]+cnt2[j] - (a[i][j]==0))%2 == 1) cout << 1;
      else cout << 0;
    }
    cout << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 7032
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

// clang-format off
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using vii = vector<int>;
using vll = vector<ll>;
using vdd = vector<ld>;
using vvii = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvdd = vector<vector<ld>>;
using vvvii = vector<vector<vector<int>>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvdd = vector<vector<vector<ld>>>;
template<class T, class U> using P = pair<T, U>;
template<class T> using V1 = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T> using V3 = vector<vector<vector<T>>>;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n) - 1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(...) _overload3(__VA_ARGS__, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define popcnt(x) __builtin_popcountll(x)
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end());
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const ld DINF = numeric_limits<ld>::infinity();
const ll mod = 1000000007;
//const ll mod = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;
const ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> T min(const vector<T> &x) { return *min_element(all(x)); }
template<typename T> T max(const vector<T> &x) { return *max_element(all(x)); }
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.fi << ", " << p.se << ")"; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; for (auto &z : v) os << z << " "; os << "]"; return os; }
#ifdef _DEBUG
#define show(x) cout << #x << " = " << x << endl;
#else
#define show(x)
#endif
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll rem(ll a, ll b) { return (a % b + b) % b; }
// clang-format on

// using mint = modint998244353;

ll modpow(ll a, ll N, ll mod) {
    ll res = 1;
    // 例えば3=101(2)なので、下位bitから順に1ならa倍する
    while (N) {
        if (N & 1) res = res * a % mod;
        a = a * a % mod;
        N >>= 1;
    }
    return res;
}

int main() {
    // IOS;
    int h, w;
    cin >> h >> w;
    vvii g(h, vii(w, 0));
    rep(i, h) rep(j, w) cin >> g[i][j];
    vii H(h, 0), W(w, 0);
    rep(i, h) rep(j, w) {
        H[i] ^= g[i][j];
        W[j] ^= g[i][j];
    }
    vvii ans(h, vii(w, 0));
    rep(i, h) rep(j, w) ans[i][j] = (g[i][j] ^ H[i] ^ W[j] ^ 1);
    rep(i, h) {
        rep(j, w) {
            cout << ans[i][j];
            if (j != w - 1)
                cout << " ";
            else
                cout << endl;
        }
    }
    return 0;
}

/*
メモ
ライツアウトの一種
(i,j)だけひっくり返すことが、i行とj列全てのマスに対して操作することで実現可能
ひっくり返すをXORと考えると、各行各列ごとに累積XORみたいなものを前計算できるのでO(HW)になる
前計算しなくてもO(HW(H+W))でOK(昔は通らなかったのかもしれない)
*/
accuracy: 1
time_ms: 120
memory_kb: 11348
final_rank: 14

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int h, w; cin >> h >> w;
  vector<vector<int> > a(h, vector<int>(w)); REP(i, h) REP(j, w) cin >> a[i][j];
  vector<int> yoko(h, 0), tate(w, 0);
  REP(i, h) REP(j, w) {
    if (a[i][j] == 0) {
      ++yoko[i];
      ++tate[j];
    }
  }
  REP(i, h) REP(j, w) cout << ((yoko[i] + tate[j] + 1 - a[i][j]) & 1 ? 1 : 0) << (j + 1 == w ? '\n' : ' ');
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 6836
final_rank: 4

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int table[1000][1000],row_memo[1000],col_memo[1000];

int main(){

	int H,W;
	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++)row_memo[row] = 0;
	for(int col = 0; col < W; col++)col_memo[col] = 0;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			scanf("%d",&table[row][col]);
			if(table[row][col] == 0){
				row_memo[row]++;
				col_memo[col]++;
			}
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(col > 0)printf(" ");
			printf("%d",((1-table[row][col])+row_memo[row]+col_memo[col])%2);
		}
		printf("\n");
	}

	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 7128
final_rank: 5

code_snippet: #include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int h,w;
int a[1010][1010];
int fh[1010],fw[1010];

int main(void){
	cin >> h >> w;
	rep(i,h)rep(j,w) cin >> a[i][j];

	rep(i,h)rep(j,w){
		if(a[i][j]==0){
			fh[i]++;
			fw[j]++;
		}
	}
	
	rep(i,h){
		rep(j,w) cout << (j?" ":"") << (fh[i]+fw[j]+(a[i][j]==0))%2;
		cout << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 7000
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int h,w;
bool yoko[2000],tate[2000];
bool mp[2000][2000];
bool res[2000][2000];

int main(){
  cin>>h>>w;
  REP(i,h)REP(j,w)cin>>mp[i][j];
  REP(i,h)REP(j,w){
    if(!mp[i][j]){
      res[i][j]^=true;
      yoko[i]^=true;
      tate[j]^=true;
    }
  }
  REP(i,h){
    REP(j,w){
      cout<<(res[i][j]^yoko[i]^tate[j])<<(j==w-1?"":" ");
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 7224
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	int h,w,b[1000][1000];
	cin >> h >> w;
	rep(i,0,h) rep(j,0,w) cin >> b[i][j];

	int cnt[1000][1000]={};
	rep(i,0,h){
		rep(j,0,w){
			if(!b[i][j]){
				rep(k,0,w) if(k!=j) ++cnt[i][k];
				rep(k,0,h) if(k!=i) ++cnt[k][j];
				++cnt[i][j];
			}
		}
	}

	rep(i,0,h){
		rep(j,0,w){
			cout << cnt[i][j]%2;
			if(j==w-1) cout << endl;
			else cout << ' ';
		}
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}
accuracy: 1
time_ms: 2340
memory_kb: 9016
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;

int b[1000000];
int r[1000],c[1000];

int main(){
  int h,w;
  scanf("%d%d",&h,&w);

  for(int i=0;i<h*w;i++){
    scanf("%d",b+i);
    if(!b[i])r[i/w]++, c[i%w]++;
  }

  for(int i=0;i<h*w;i++){
    printf("%d%c",(r[i/w]+c[i%w]+1-b[i])&1,i%w==w-1?'\n':' ');
  }
}
accuracy: 1
time_ms: 200
memory_kb: 5100
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;

int b[1000][1000];

int main(){
  int h,w;
  scanf("%d%d",&h,&w);
  vector<int> r(h,0), c(w,0);

  for(int i=0;i<h;i++)for(int j=0;j<w;j++){
      scanf("%d",&b[i][j]);
      if(!b[i][j])r[i]++, c[j]++;
    }

  for(int i=0;i<h;i++)for(int j=0;j<w;j++){
      printf("%d%c",(r[i]+c[j]+1-b[i][j])&1,j+1==w?'\n':' ');
    }
}
accuracy: 1
time_ms: 190
memory_kb: 5104
final_rank: 6

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



const int MAX1 = 2020;
const int MAX2 = 2020;
int SIZE1, SIZE2;

template<class T> struct BIT2D {    
    T dat[2][2][MAX1 + 1][MAX2 + 1];
    
    void init(int n = 1, int m = 1) {
        SIZE1 = n, SIZE2 = m;
        for (int i = 0; i <= SIZE1; ++i) 
            for (int j = 0; j <= SIZE2; ++j) 
                dat[0][0][i][j] = dat[0][1][i][j] = dat[1][0][i][j] = dat[1][1][i][j] = 0;
    }
    
    inline void subsub_add(int f, int s, int a, int b, T x) {
        for (int i = a; i <= SIZE1; i += i & -i) 
            for (int j = b; j <= SIZE2; j += j & -j) 
                dat[f][s][i][j] = dat[f][s][i][j] + x;
    }
    
    inline void sub_add(int a1, int a2, long long x) {
        subsub_add(0, 0, a1, a2, x*(a1-1)*(a2-1));
        subsub_add(1, 0, a1, a2, -x*(a1-1));
        subsub_add(0, 1, a1, a2, -x*(a2-1));
        subsub_add(1, 1, a1, a2, x);
    }
    
    // a1 <= x < b1, a2 <= y < b2
    inline void add(int a1, int a2, int b1, int b2, long long x) {
        sub_add(a1, a2, x);
        sub_add(a1, b2, -x);
        sub_add(b1, a2, -x);
        sub_add(b1, b2, x);
    }
    
    inline T subsub_sum(int f, int s, int a, int b) {
        T res = 0;
        for (int i = a; i > 0; i -= i & -i) 
            for (int j = b; j > 0; j -= j & -j) 
                res = res + dat[f][s][i][j];
        return res;
    }
    
    inline T sub_sum(int a1, int a2) {
        T res = 0;
        res += subsub_sum(0, 0, a1-1, a2-1);
        res += subsub_sum(1, 0, a1-1, a2-1) * (a2-1);
        res += subsub_sum(0, 1, a1-1, a2-1) * (a1-1);
        res += subsub_sum(1, 1, a1-1, a2-1) * (a1-1) * (a2-1);
        return res;
    }
    
    // a1 <= x < b1, a2 <= y < b2
    inline T sum(int a1, int a2, int b1, int b2) {
        return sub_sum(b1, b2) - sub_sum(a1, b2) - sub_sum(b1, a2) + sub_sum(a1, a2);
    }
    
    void print() {
        for (int i = 1; i <= SIZE1; ++i) {
            for (int j = 1; j <= SIZE2; ++j) 
                cout << sum(i, j, i+1, j+1) << ",";
            cout << endl;
        }
    }
};

BIT2D<long long > bit;




int H, W;
int a[2000][2000];


int main() {
    while (cin >> H >> W) {
        bit.init(H, W);
        
        for (int i = 1; i <= H; ++i) for (int j = 1; j <= W; ++j) {
            cin >> a[i][j];
            if (a[i][j] == 0) {
                bit.add(i, 1, i+1, W+1, 1);
                bit.add(1, j, H+1, j+1, 1);
                bit.add(i, j, i+1, j+1, -1);
            }
        }
        for (int i = 1; i <= H; ++i) {
            for (int j = 1; j <= W; ++j) {
                long long sum = bit.sum(i, j, i+1, j+1);
                cout << sum%2;
                if (j != W) cout << " ";
            }
            cout << endl;
        }
    }
    
    return 0;
}
accuracy: 1
time_ms: 2080
memory_kb: 81024
final_rank: 20

code_snippet: #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int h, w;
	cin >> h >> w;

	vector<vector<int> > a(h, vector<int>(w));
	vector<int> col(w, 0), row(h, 0);
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			cin >> a[i][j];

			if(!a[i][j]) {
				++col[j];
				++row[i];
			}
		}
	}

	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if((col[j] + row[i] + (1 - a[i][j])) & 1)
				cout << "1";
			else
				cout << "0";

			cout << (j + 1 == w ? "\n" : " ");
		}
	}

	return EXIT_SUCCESS;
}
accuracy: 1
time_ms: 120
memory_kb: 4964
final_rank: 1

code_snippet: #define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int a[1000][1000];
int hh[1000];
int ww[1000];

int main(){
  const int h = getInt();
  const int w = getInt();

  REP(i,h) REP(j,w){
    a[i][j] = getInt();
    hh[i] += a[i][j];
    ww[j] += a[i][j];
  }

  REP(i,h) REP(j,w)
    printf("%d%c", (3 * a[i][j] + hh[i] + ww[j] + 1) % 2, j == w - 1 ? '\n' : ' ');

  return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 4944
final_rank: 7

code_snippet: #include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;

    vector<vector<int> > a(h, vector<int>(w));
    vector<vector<int> > b(h, vector<int>(w, 0));
    vector<bool> y(h, false), x(w, false);
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            cin >> a[i][j];
            if(!a[i][j]){
                b[i][j] = 1;
                y[i] = !y[i];
                x[j] = !x[j];
            }
        }
    }

    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            b[i][j] ^= (y[i] ^ x[j])? 1:0;
        }
    }

    for(int i=0; i<h; ++i){
        for(int j=0; j<w-1; ++j)
            cout << b[i][j] << ' ';
        cout << b[i][w-1] << endl;
    }
}
accuracy: 1
time_ms: 240
memory_kb: 8924
final_rank: 17

code_snippet: #include <iostream>
#include <cstring>
using namespace std;

int h, w;
int t[1002][1002];
int col[1002], row[1002];

void solve(){
  memset(col, 0, sizeof(col));
  memset(row, 0, sizeof(row));

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(t[i][j] == 0){
        col[j]++;
        row[i]++;
      }
    }
  }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(j != 0) cout << " ";
      cout << (!t[i][j] + col[j] + row[i]) % 2;
    }
    cout << endl;
  }
}

int main(){
  while(cin >> h >> w){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> t[i][j];
      }
    }

    solve();
  }
}
accuracy: 1
time_ms: 220
memory_kb: 5084
final_rank: 9

code_snippet: #include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, m, a[1024][1024], b[1024][1024], x[1024], y[1024];
inline int f(int i, int j) { return (a[i][j]+b[i][j]+x[i]+y[j]) % 2; }

int main() {
    scanf("%d%d", &n, &m);
    rep (i, n) rep (j, m) scanf("%d", a[i]+j);
    rep (k, n-1) {
        int c = 0;
        rep (i, m) c += f(k, i) != f(k+1, i);
        rep (i, m) if ((f(k, i)==f(k+1, i)) == c%2) b[k+1][i]++, y[i]++;
        x[k+1] = c;
    }
    int s = 0;
    rep (i, m) if (f(0, i)) s++;
    rep (i, m) if (f(0, i) == s%2) rep (k, n) b[k][i]++;
    rep (i, n) rep (j, m) printf("%d%c", b[i][j]%2, "\n "[j+1<m]);
    return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 9224
final_rank: 15

code_snippet: #include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, m, a[1024][1024], b[1024][1024], x[1024], y[1024];
inline int f(int i, int j) { return (a[i][j]+b[i][j]+x[i]+y[j]) % 2; }

int main() {
    scanf("%d%d", &n, &m);
    rep (i, n) rep (j, m) scanf("%d", a[i]+j);
    rep (k, n-1) {
        int c = 0;
        rep (i, m) c += f(k, i) != f(k+1, i);
        if (c%2) {
            rep (i, m) if (f(k, i) == f(k+1, i)) b[k+1][i]++, y[i]++;
        }
        else {
            rep (i, m) if (f(k, i) != f(k+1, i)) b[k+1][i]++, y[i]++;
        }
        x[k+1] = c;
    }
    int s = 0;
    rep (i, m) if (f(0, i)) s++;
    if (s%2) {
        rep (i, m) if (f(0, i)) rep (k, n) b[k][i]++;
    }
    else {
        rep (i, m) if (!f(0, i)) rep (k, n) b[k][i]++;
    }
    rep (i, n) rep (j, m) printf("%d%c", b[i][j]%2, "\n "[j+1<m]);
    return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 9224
final_rank: 15

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int h,w;cin>>h>>w;){
		vvi grid(h,vi(w));
		rep(i,h) rep(j,w) cin>>grid[i][j];
		
		vvi hgrid(h,vi(w+1)),vgrid(h+1,vi(w));
		rep(i,h) rep(j,w) if(!grid[i][j]){
			hgrid[i][0]++; hgrid[i][w]--;
			hgrid[i][j]--; hgrid[i][j+1]++;
			vgrid[0][j]++; vgrid[h][j]--;
		}
		rep(i,h) rep(j,w){
			hgrid[i][j+1]+=hgrid[i][j];
			vgrid[i+1][j]+=vgrid[i][j];
		}
		
		vvi res(h,vi(w));
		rep(i,h) rep(j,w)
			res[i][j]=hgrid[i][j]+vgrid[i][j]&1;
		
		rep(i,h) rep(j,w)
			cout<<res[i][j]<<(j==w-1?'\n':' ');
	}
	
	return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 16844
final_rank: 18

code_snippet: #include<iostream>
#include<cstdio>
 
using namespace std;
 
 
int main(){
  int h,w,imap[1010][1010],H[1010],W[1010];
  for(int i=0;i<1010;i++)H[i] = W[i] = 0;
  cin >> h >> w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> imap[i][j];
      if(imap[i][j] == 0)H[i]++,W[j]++;
    }
  }
 
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      (H[i]+W[j]-1+imap[i][j])%2==0?cout << 0:cout << 1;
      if(j != w-1)cout << ' ';
    }
    cout << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 5120
final_rank: 11