Submission #8343183


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/












int N, M;
string B[50];
//---------------------------------------------------------------------------------------------------
int count(int sy, int ty, char c) { // [sy, ty)
	int res = 0;
	rep(y, sy, ty) rep(x, 0, M) if (B[y][x] == c) res++;
	return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> B[i];

	int ans = inf;
	rep(white, 1, N) rep(blue, 1, N) {
		int red = N - white - blue;
		if (0 < red) {
			int tot = 0;
			tot += white * M - count(0, white, 'W');
			tot += blue * M - count(white, white + blue, 'B');
			tot += red * M - count(white + blue, white + blue + red, 'R');
			chmin(ans, tot);
		}
	}
	cout << ans << endl;
}





Submission Info

Submission Time
Task C - ロシアの旗 (Russian Flag)
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2056 Byte
Status AC
Exec Time 5 ms
Memory 256 KiB

Judge Result

Set Name set01 set02 set03 set04 set05
Score / Max Score 20 / 20 20 / 20 20 / 20 20 / 20 20 / 20
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
set01 data1
set02 data2
set03 data3
set04 data4
set05 data5
Case Name Status Exec Time Memory
data1 AC 1 ms 256 KiB
data2 AC 1 ms 256 KiB
data3 AC 5 ms 256 KiB
data4 AC 5 ms 256 KiB
data5 AC 5 ms 256 KiB