Problem:
コイン集め 2 (Coin Collecting 2)
問題文
机の上に，縦
H
行，横
W
列の長方形状にコインが並べられている．
最初，上から
i
行目 (
1 ≦ i ≦ H
)，左から
j
列目 (
1 ≦ j ≦ W
) のコインは，
S
i,j
=
#
のとき表面，
S
i,j
=
.
のとき裏面が見えている状態である．
葵と凛は，これらのコインを用いてゲームを行うことにした．ゲームは以下のような流れで行われる．
葵がどれか
1
つの行を選び，その行のコインをすべてひっくり返す．
凛がどれか
1
つの列を選び，その列のコインをすべてひっくり返す．
葵が，表面が見えるコインをすべて獲得する．また凛が，裏面が見えるコインをすべて獲得する．
葵と凛はそれぞれ，できるだけ多くのコインを獲得したい．
ゲーム開始時のコインの状態が与えられたとき，
両者が最善を尽くした場合にそれぞれが獲得できるコインの枚数を求めるプログラムを作成せよ．
制約
H ≧ 1
．
W ≧ 1
．
H × W ≦ 500000
．
S
i, j
は
#
，
.
のいずれかである (
1 ≦ i ≦ H
，
1 ≦ j ≦ W
)．
H, W
は整数である．
入力
入力は以下の形式で与えられる．
H
W
S
1,1
S
1,2
…
S
1,W
S
2,1
S
2,2
…
S
2,W
︙
S
H,1
S
H,2
…
S
H,W
出力
葵と凛の得点をこの順に空白区切りで出力せよ．
入出力例
入力例 1
1 1
#
出力例 1
1 0
この入力例では，必ず以下のようにゲームが進行する．
まず，葵が
1
行目のすべてのコインをひっくり返す．
次に，凛が
1
列目のすべてのコインをひっくり返す．
このとき，唯一のコインの見える面は「表→裏→表」と変化するため，葵が
1
枚のコインを獲得できるが，凛はコインを獲得できない．したがって，
1
，
0
をこの順に空白区切りで出力する．
入力例 2
5 5
#####
####.
###..
##...
#....
出力例 2
13 12
両者が最善を尽くした場合の，ゲームの進行の一例を下図に示す．
入力例 3
1 40
..........##########..........##########
出力例 3
19 21
入力例 4
7 1
#
#
#
#
#
#
#
出力例 4
1 6
入力例 5
5 5
.###.
...##
..##.
.##..
##...
出力例 5
11 14
入力例 6
10 40
........................................
..######.....####.....#####.....####....
.....#......#....#......#......#........
.....#......#....#......#......#........
.....#......#....#......#......#........
.....#......#....#......#......#..####..
..#..#......#....#......#......#....#...
..#..#......#....#......#......#....#...
...##........####.....#####.....####....
........................................
出力例 6
104 296
情報オリンピック日本委員会
作 『日本情報オリンピック第3回女性部門 本選 競技課題』

Submitted solutions:

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	auto H=in(),W=in();
	vvll M(H,vll(W,0));
	ll F=0;
	REP(i,H){
		auto S=in<string>();
		REP(j,W){
			if(S[j]=='#'){
				M[i][j]=1;
				F++;
			}
		}
	}
	vll C(W,0);
	REP(j,W){
		REP(i,H){
			C[j] += M[i][j];
		}
	}
	ll AF=0,AB=H*W;
	REP(i,H){
		vll LC=C;
		ll MC=0;
		ll LF=F;
		REP(j,W){
			if(M[i][j]){
				LF--;
				LC[j]--;
				chmax(MC,LC[j]);
			}
			else{
				LF++;
				LC[j]++;
				chmax(MC,LC[j]);
			}
		}
		ll X = H-MC;
		ll LAF = LF-MC+X;
		ll LAB = H*W-LAF;
		if(LAF>AF){
			AF = LAF;
			AB = LAB;
		}
	}
	out(AF,AB);
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 30460
final_rank: 11

code_snippet: #include <vector>
#include <string>
#include <deque>
#include <tuple>
#include <climits>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <random>
#include <cfloat>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>
#include <variant>
#include <bitset>
#include <unordered_map>
#include <array>
#include <cmath>
#include <map>
#include <optional>
#include <cassert>
#include <filesystem>
#include <mutex>
#include <thread>
#include <functional>
#include <fstream>
#include <chrono>
#include <stack>
#include <array>


int main() {
	int height, width; std::cin >> height >> width;
	std::vector<std::string> state(height);
	for (auto& line : state) {
		std::cin >> line;
	}
	std::vector<int> countByRow(height, 0), countByColumn(width, 0);
	for (auto i = 0; i < height; ++i) {
		for (auto j = 0; j < width; ++j) {
			if (state[i][j] == '#') {
				countByRow[i] += 1;
				countByColumn[j] += 1;
			}
		}
	}
	const auto sum{ std::accumulate(countByRow.begin(), countByRow.end(), 0) };
	int result{ 0 };
	for (auto i = 0; i < height; ++i) {
		const auto diffRow{ width - countByRow[i] * 2 };
		int worst{ INT_MAX };
		for (auto j = 0; j < width; ++j) {
			const auto diffColumn{ height - countByColumn[j] * 2 };
			const auto current{ sum + diffRow + diffColumn + (state[i][j] == '#' ? 2 : -2) };
			worst = std::min(worst, current);
		}
		result = std::max(result, worst);
	}
	std::cout << result << " " << (height * width - result) << '\n';
}
accuracy: 1
time_ms: 30
memory_kb: 20580
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define sz(A) ((ll)A.size())
#define ALL(A) A.begin(),A.end()
int main(){
    int H,W;cin>>H>>W;
    vector<string>S(H);
    REP(i,H)cin>>S[i];
    vi X(H),Y(W);
    REP(i,H)REP(j,W)if(S[i][j]=='#')X[i]++,Y[j]++;
    vvi Q(H,vi(W));
    REP(i,H)REP(j,W)Q[i][j]=H-2*X[i]+W-2*Y[j]+(S[i][j]=='#'?2:-2);
    ll ma=-1e18;
    REP(i,H){
        ll m=*min_element(ALL(Q[i]));
        ma=max(ma,m);
    }
    REP(i,H)REP(j,W)if(S[i][j]=='#')ma++;
    cout<<ma<<" "<<H*W-ma<<endl;
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 49956
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int h, w;
vector<int> cnt(500009);
vector<int> ci(500009);
vector<string> c(500009);

int si(int px) {
    for (int i = 0; i < w; i++) {
        if (c[px][i] == '#')
            cnt[i]--;
        if (c[px][i] == '.')
            cnt[i]++;
    }
    int mo = -1;
    int mi = -1;
    for (int j = 0; j < w; j++) {
        if (mo < cnt[j]) {
            mo = cnt[j];
            mi = j;
        }
    }
    cnt[mi] = h - cnt[mi];
    int ret = 0;
    for (int j = 0; j < w; j++)
        ret += cnt[j];
    return ret;
}

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

    cin >> h >> w;
    for (int i = 0; i < h; i++)
        cin >> c[i];
    
    for (int j = 0; j < w; j++) {
        cnt[j] = 0;
        for (int i = 0; i < h; i++)
            if (c[i][j] == '#')
                cnt[j]++;
        ci[j] = cnt[j];
    }
    
    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++)
            cnt[j] = ci[j];
        ans = max(ans, si(i));
    }
    
    cout << ans << ' ' << h * w - ans << '\n';
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 23732
final_rank: 7

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() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    int res = 0;
    vector<int> ch(h), cw(w);
    int sum = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                ch[i] += 1, cw[j] += 1;
                sum += 1;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        int mi = h * w;
        for (int j = 0; j < w; j++) {
            int uo = sum - ch[i] + (w - ch[i]);
            if (s[i][j] == '#') {
                cw[j] -= 1;
            } else {
                cw[j] += 1;
            }
            uo += (h - cw[j]) - cw[j];
            mi = min(mi, uo);
            if (s[i][j] == '#') {
                cw[j] += 1;
            } else {
                cw[j] -= 1;
            }
        }
        res = max(res, mi);
    }

    cout << res << " " << h * w - res << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 20780
final_rank: 3

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll H, W;
  cin >> H >> W;
  vc<string> S(H);
  rep(i, H) cin >> S[i];
  vi cols(W, 0);
  rep(i, H) rep(j, W) {
    if (S[i][j] == '#') {
      cols[j]++;
    }
  }
  ll aoi = 0;
  rep(i, H) {
    vi c(cols);
    rep(j, W) {
      if (S[i][j] == '#') c[j]--;
      else c[j]++;
    }
    ll max_r=-1, max_j=-1;
    rep(j, W) {
      if (chmax(max_r, c[j])) max_j = j;
    }
    c[max_j] = H - c[max_j];
    chmax(aoi, SUM(c));
  }
  print(aoi, H*W-aoi);
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 18768
final_rank: 1

code_snippet: #line 1 "a.cpp"
#define PROBLEM ""
#line 2 "/home/kuhaku/home/github/algo/lib/template/template.hpp"
#pragma GCC target("sse4.2,avx2,bmi2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = M_PI;
#line 3 "/home/kuhaku/home/github/algo/lib/template/macro.hpp"
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
#line 3 "/home/kuhaku/home/github/algo/lib/template/sonic.hpp"
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(20);
    }

    constexpr void operator()() const {}
} sonic;
#line 5 "/home/kuhaku/home/github/algo/lib/template/atcoder.hpp"
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) {
        os << (it == v.begin() ? "" : " ") << *it;
    }
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
template <typename T, typename... Args>
auto make_vector(T x, int arg, Args... args) {
    if constexpr (sizeof...(args) == 0) return std::vector<T>(arg, x);
    else return std::vector(arg, make_vector<T>(x, args...));
}
void Yes(bool is_correct = true) {
    std::cout << (is_correct ? "Yes" : "No") << '\n';
}
void No(bool is_not_correct = true) {
    Yes(!is_not_correct);
}
void YES(bool is_correct = true) {
    std::cout << (is_correct ? "YES" : "NO") << '\n';
}
void NO(bool is_not_correct = true) {
    YES(!is_not_correct);
}
void Takahashi(bool is_correct = true) {
    std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n';
}
void Aoki(bool is_not_correct = true) {
    Takahashi(!is_not_correct);
}
#line 3 "a.cpp"

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    cin >> s;

    int a = 0, b = 0;
    vector<int> c(h), d(w);
    rep (i, h) {
        rep (j, w) {
            if (s[i][j] == '#') {
                ++a;
                ++c[i];
                ++d[j];
            } else {
                ++b;
            }
        }
    }

    vector<int> ys(h);
    rep (i, h) {
        a -= c[i] * 2 - w;
        b += c[i] * 2 - w;
        rep (j, w) {
            if (s[i][j] == '#') {
                --d[j];
            } else {
                ++d[j];
            }
            a -= d[j] * 2 - h;
            b += d[j] * 2 - h;
            chmax(ys[i], b);
            a += d[j] * 2 - h;
            b -= d[j] * 2 - h;
            if (s[i][j] == '#') {
                ++d[j];
            } else {
                --d[j];
            }
        }
        a += c[i] * 2 - w;
        b -= c[i] * 2 - w;
    }
    int ans = *min_element(all(ys));
    co(h * w - ans, ans);

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 22704
final_rank: 6

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

int h, w;
int cnt[500009];
int ci[500009];
string c[500009];

int si(int px) {
  for (int i = 0; i < w; i++) {
    if (c[px][i] == '#')
      cnt[i]--;
    if (c[px][i] == '.')
      cnt[i]++;
  }
  int mo = -1;
  int mi = -1;
  for (int j = 0; j < w; j++) {
    if (mo < cnt[j]) {
      mo = cnt[j];
      mi = j;
    }
  }
  cnt[mi] = h - cnt[mi];
  int ret = 0;
  for (int j = 0; j < w; j++)
    ret += cnt[j];
  return ret;
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> c[i];
  for (int j = 0; j < w; j++) {
    cnt[j] = 0;
    for (int i = 0; i < h; i++)
      if (c[i][j] == '#')
        cnt[j]++;
    ci[j] = cnt[j];
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      cnt[j] = ci[j];
    ans = max(ans, si(i));
  }
  cout << ans << ' ' << h * w - ans << '\n';
}
accuracy: 1
time_ms: 80
memory_kb: 30520
final_rank: 13

code_snippet: #define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w;
  cin>>h>>w;
  vector<string> S(h);
  rep(i,h) cin>>S[i];
  vector<int> H(h),W(w);
  int cnt=0;
  rep(i,h) rep(j,w){
    if(S[i][j]=='.'){
      H[i]++;
      W[j]++;
      cnt++;
    }
  }
  int mi=h*w+1;
  rep(i,h){
    int ma=-h*w-1;
    rep(j,w){
      int t=w+h-2*H[i]-2*W[j];
      if(S[i][j]=='#') ma=max(ma,t-2);
      else ma=max(ma,t+2);
    }
    mi=min(mi,ma);
  }
  cout<<h*w-mi-cnt<<" "<<mi+cnt<<endl;
  
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 20792
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}



int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
   
    ll H,W;
    cin>>H>>W;
    vll HN(H,0),WN(W,0);
    vector<string> S(H);
    ll cnt=0;
    rep(h,H){
        cin>>S[h];
        rep(w,W){
            if(S[h][w]=='#'){
                HN[h]++;
                WN[w]++;
                cnt++;
            }
        }
    }
    ll an=0;
    rep(h,H){
        ll d=cnt+(W-HN[h])-HN[h];
        ll m=1e18;
        rep(w,W){
            //cout<<d<<endl;
            if(S[h][w]=='#')WN[w]--;
            else WN[w]++;

            chmin(m,d-WN[w]+(H-WN[w]));
            if(S[h][w]=='#')WN[w]++;
            else WN[w]--;
        }
        chmax(an,m);
    }
    cout<<an<<" "<<H*W-an<<endl;
}
accuracy: 1
time_ms: 20
memory_kb: 22488
final_rank: 5

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define updiv(a, b) (((a) + (b) - 1) / (b))
using pii = pair<int,int>;
constexpr int32_t INF  = 0x3f3f3f3f;
constexpr int_fast64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p){ is >> p.first >> p.second; return (is); }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p){ os << p.first << ' ' << p.second; return (os); }
template<class T> istream& operator>>(istream& is, vector<T>& v){ for (auto &&e : v) is >> e; return (is); }
template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for (auto &&e : v) os << e << ' '; return (os); }

template<class T> inline const T& max(const vector<T> &v) { return *max_element(v.begin(), v.end()); }
template<class T> inline const T& min(const vector<T> &v) { return *min_element(v.begin(), v.end()); }
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class A, class B> using umap = unordered_map<A, B>;
template <class T> using uset = unordered_set<T>;

template <class T> using Max_Heap = __gnu_pbds::priority_queue<T, less<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Min_Heap = __gnu_pbds::priority_queue<T, greater<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class K, class V> using Umap = __gnu_pbds::gp_hash_table<K, V>;
template <class T> using Rope = __gnu_cxx::rope<T>;
using Trie = __gnu_pbds::trie<string, __gnu_pbds::null_type, __gnu_pbds::trie_string_access_traits<>, __gnu_pbds::pat_trie_tag, __gnu_pbds::trie_prefix_search_node_update>;

template <class T> void bye(T x){ cout << x << '\n'; exit(0); }

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

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

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

    vector<string> s(h);

    cin >> s;

    vector<vector<int> > mat(h, vector<int>(w));

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            mat[i][j] = (s[i][j] == '#');
        }
    }

    vector<int> r(h), c(w);
    int sum = 0;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            r[i] += mat[i][j];
            c[j] += mat[i][j];
            sum += mat[i][j];
        }
    }

    int res = 0;

    for (int i = 0; i < h; ++i) {
        int minv = h * w;
        for (int j = 0; j < w; ++j) {
            int aoi = sum;
            aoi -= r[i] + c[j];
            aoi += mat[i][j];
            aoi += w - r[i] + h - c[j];
            aoi += mat[i][j] - (1 - mat[i][j]) * 2;
            chmin(minv, aoi);
        }
        chmax(res, minv);
    }

    cout << res << ' ' << h * w - res << '\n';

    return (0);
}
accuracy: 1
time_ms: 30
memory_kb: 47932
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001


enum Type{
	Sente,
	Gote,
};


int *numOmoteCol; //列ごとの表の個数を持つ
int *numOmoteRow; //行ごとの表の数を持つ
char **buf;
int H,W;
int sumOmote = 0,sumUra = 0;


int func(Type type,int base){ //自分の得点を返却

	int ret = -BIG_NUM;

	if(type == Sente){ //どれか1つの行を選ぶ

		for(int row = 0; row < H; row++){

			int tmp = func(Gote,row);
			chmax(ret,H*W-tmp);
		}

	}else{ //どれか1つの列を選ぶ

		for(int col = 0; col < W; col++){

			//この列以外の数
			int otherOmote = sumOmote-numOmoteCol[col]; //この列以外の表の総数
			int otherUra = sumUra-(H-numOmoteCol[col]); //この列以外の裏の総数

			//先手による反転結果を反映
			int workOmote = numOmoteRow[base];
			int workUra = W-workOmote;
			//この列は無視
			if(buf[base][col] == '#'){

				workOmote--;

			}else{

				workUra--;
			}

			otherOmote = otherOmote-workOmote+workUra;
			otherUra = otherUra-workUra+workOmote;

			//この列の反転前
			int omote = numOmoteCol[col];
			int ura = H-numOmoteCol[col];

			if(buf[base][col] == '#'){

				omote--;
				ura++;

			}else{

				omote++;
				ura--;
			}

			//この列の反転後
			int nextUra = otherUra+omote;

			chmax(ret,nextUra);
		}
	}

	return ret;
}


int main(){

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

	buf = new char*[H];
	numOmoteCol = new int[W];
	numOmoteRow = new int[H];

	for(int col = 0; col < W; col++){

		numOmoteCol[col] = 0;
	}

	for(int row = 0; row < H; row++){

		numOmoteRow[row] = 0;
	}

	for(int row = 0; row < H; row++){

		buf[row] = new char[W+1];
	}

	for(int row = 0; row < H; row++){

		scanf("%s",buf[row]);
		for(int col = 0; col < W; col++){
			if(buf[row][col] == '#'){

				sumOmote++;
				numOmoteCol[col]++;
				numOmoteRow[row]++;

			}else{

				sumUra++;
			}
		}
	}

	int sente = func(Sente,-1);
	int gote = H*W-sente;

	printf("%d %d\n",sente,gote);

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 24700
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001


enum Type{
	Sente,
	Gote,
};


int *numOmoteCol; //列ごとの表の個数を持つ
int *numOmoteRow; //行ごとの表の数を持つ
char **buf;
int H,W;
int sumOmote = 0,sumUra = 0;


int func(Type type,int base){ //自分の得点を返却

	int ret = -BIG_NUM;

	if(type == Sente){ //どれか1つの行を選ぶ

		for(int row = 0; row < H; row++){

			int tmp = func(Gote,row);
			chmax(ret,H*W-tmp);
		}

	}else{ //どれか1つの列を選ぶ

		for(int col = 0; col < W; col++){

			//この列以外の数
			int otherOmote = sumOmote-numOmoteCol[col]; //この列以外の表の総数
			int otherUra = sumUra-(H-numOmoteCol[col]); //この列以外の裏の総数

			//printf("otherOmote:%d otherUra:%d\n",otherOmote,otherUra);

			//先手による反転結果を反映
			int workOmote = numOmoteRow[base];
			int workUra = W-workOmote;
			//この列は無視
			if(buf[base][col] == '#'){

				workOmote--;

			}else{

				workUra--;
			}

			//printf("workOmote:%d workUra:%d\n",workOmote,workUra);

			otherOmote = otherOmote-workOmote+workUra;
			otherUra = otherUra-workUra+workOmote;

			//printf("otherOmote:%d otherUra:%d\n",otherOmote,otherUra);

			//この列の反転前
			int omote = numOmoteCol[col];
			int ura = H-numOmoteCol[col];

			//printf("列%dの反転前 omote:%d 裏:%d\n",col,omote,ura);

			if(buf[base][col] == '#'){

				omote--;
				ura++;

			}else{

				omote++;
				ura--;
			}

			//printf("列%dの反転後 omote:%d 裏:%d\n",col,omote,ura);

			//この列の反転後
			int nextOmote = otherOmote+ura;
			//printf("nextOmote:%d otherOmote:%d ura:%d\n",nextOmote,otherOmote,ura);
			int nextUra = otherUra+omote;
			//printf("nextUra:%d otherUra:%d omote:%d\n",nextUra,otherUra,omote);

			chmax(ret,nextUra);
		}
	}

	return ret;
}


int main(){

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

	buf = new char*[H];
	numOmoteCol = new int[W];
	numOmoteRow = new int[H];

	for(int col = 0; col < W; col++){

		numOmoteCol[col] = 0;
	}

	for(int row = 0; row < H; row++){

		numOmoteRow[row] = 0;
	}

	for(int row = 0; row < H; row++){

		buf[row] = new char[W+1];
	}

	for(int row = 0; row < H; row++){

		scanf("%s",buf[row]);
		for(int col = 0; col < W; col++){
			if(buf[row][col] == '#'){

				sumOmote++;
				numOmoteCol[col]++;
				numOmoteRow[row]++;

			}else{

				sumUra++;
			}
		}
	}

	//printf("num0:%d num1:%d\n",sumOmote,sumUra);

	int sente = func(Sente,-1);
	int gote = H*W-sente;

	printf("%d %d\n",sente,gote);

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 24716
final_rank: 10

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, cnt = 0;
    cin >> h >> w;
    vector<string> A(h);
    vector<int> Y(h), X(w);
    for(int y = 0; y < h; y++){
        cin >> A[y];
        for(int x = 0; x < w; x++){
            if(A[y][x] == '#'){
                Y[y]++;
                X[x]++;
                cnt++;
            }else{
                Y[y]--;
                X[x]--;
                cnt--;
            }
        }
    }
    int ans = -(1 << 30);
    for(int y = 0; y < h; y++){
        int mn = 1 << 30;
        for(int x = 0; x < w; x++){
            mn = min(mn, cnt - 2 * Y[y] - 2 * X[x] + (A[y][x] == '#' ? 4 : -4) );
        }
        ans = max(ans, mn);
    }
    int v = (ans + h * w) / 2, v2 = h * w - v;
    cout << v << " " << v2 << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 20704
final_rank: 2