結果

問題 No.421 しろくろチョコレート
ユーザー koyumeishi
提出日時 2015-02-13 23:23:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,514 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 77,476 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-16 08:41:10
合計ジャッジ時間 2,651 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

//嘘greedy

int greedy_yoko(int n, int m, vector<string> v){
	int ans = 0;
	string s = "wb";
	int cnt_w = 0;
	int cnt_b = 0;
	
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(v[i][j] == s[(i+j)%2]){
				v[i][j] = '.';

				if(j+1<m && v[i][j+1] == s[(i+j+1)%2]){
					v[i][j+1] = '.';
					ans += 100;
				}else{
					if(i+1<n && v[i+1][j] == s[(i+1+j)%2]){
						v[i+1][j] = '.';
						ans += 100;
					}else{
						( ((i+j)%2==0)? cnt_w: cnt_b )++;
					}
				}
			}
		}
	}
	

	ans += min(cnt_w, cnt_b)*10;
	ans += max(cnt_w, cnt_b) - min(cnt_w, cnt_b);

	return ans;
}

int greedy_tate(int n, int m, vector<string> v){
	int ans = 0;
	string s = "wb";
	int cnt_w = 0;
	int cnt_b = 0;

	for(int j=0; j<m; j++){
		for(int i=0; i<n; i++){
			if(v[i][j] == s[(i+j)%2]){
				v[i][j] = '.';

				if(i+1<n && v[i+1][j] == s[(i+1+j)%2]){
					v[i+1][j] = '.';
					ans += 100;
				}else{
					if(j+1<m && v[i][j+1] == s[(i+j+1)%2]){
					v[i][j+1] = '.';
						ans += 100;
					}else{
						( ((i+j)%2==0)? cnt_w: cnt_b )++;
					}
				}
			}
		}
	}

	ans += min(cnt_w, cnt_b)*10;
	ans += max(cnt_w, cnt_b) - min(cnt_w, cnt_b);

	return ans;
}


int main(){
	int n,m;
	cin >> n >> m;
	vector<string> v(n);
	for(int i=0; i<n; i++){
		cin >> v[i];
	}

	cout << max(greedy_yoko(n,m,v), greedy_tate(n,m,v)) << endl;
	return 0;
}
0