結果

問題 No.348 カゴメカゴメ
ユーザー gasingasin
提出日時 2016-03-05 13:29:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,922 bytes
コンパイル時間 1,818 ms
コンパイル使用メモリ 175,452 KB
実行使用メモリ 35,300 KB
最終ジャッジ日時 2023-10-24 19:53:36
合計ジャッジ時間 7,733 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
34,036 KB
testcase_01 WA -
testcase_02 TLE -
testcase_03 AC 56 ms
34,132 KB
testcase_04 AC 11 ms
28,940 KB
testcase_05 AC 12 ms
29,908 KB
testcase_06 AC 10 ms
28,968 KB
testcase_07 AC 11 ms
28,960 KB
testcase_08 AC 10 ms
28,936 KB
testcase_09 AC 11 ms
29,008 KB
testcase_10 WA -
testcase_11 AC 11 ms
28,988 KB
testcase_12 WA -
testcase_13 AC 11 ms
29,228 KB
testcase_14 WA -
testcase_15 AC 33 ms
29,916 KB
testcase_16 AC 10 ms
28,960 KB
testcase_17 AC 10 ms
28,960 KB
testcase_18 AC 10 ms
28,960 KB
testcase_19 AC 11 ms
28,960 KB
testcase_20 AC 11 ms
29,040 KB
testcase_21 AC 10 ms
29,052 KB
testcase_22 AC 11 ms
28,964 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef pair<int,int> P;

bool g[1000][1000];
int id[1000][1000];
bool did[1000000];
bool checked[1000000];
bool saw[1000000];
int num[1000000];
int n, m;
int x = 0;
vector<int> edge[1000000];

int func(int a, int type){
	saw[a] = true;
	int ret = 0;
	if(type == 0) ret += num[a];
	rep(i,edge[a].size()){
		int e = edge[a][i];
		if(checked[e]) continue;
		if(saw[e]) continue;
		ret += func(e,(type+1)%2);
	}
	return ret;
}

int main(){
	cin >> n >> m;
	rep(i,n){
		string str;
		cin >> str;
		rep(j,m){
			if(str[j] == 'x') g[i][j] = true;
			else g[i][j] = false;
		}
	}
	rep(i,n) rep(j,m){
		if(!g[i][j]) continue;
		if(id[i][j] != 0) continue;
		x++;
		int cnt = 1;
		queue<P> que;
		que.push(P(i,j));
		id[i][j] = x;
		while(true){
			if(que.size() == 0) break;
			P q = que.front();
			que.pop();
			for(int k = -1; k <= 1; k++) for(int l = -1; l <= 1; l++){
				if(0>q.first+k||q.first+k>=n) continue;
				if(0>q.second+l||q.second+l>=m) continue;
				if(id[q.first+k][q.second+l] != 0 || g[q.first+k][q.second+l] == false) continue;
				que.push(P(q.first+k,q.second+l));
				id[q.first+k][q.second+l] = x;
				cnt++;
			}
		}
		num[x] = cnt;
	}
	rep(i,n) rep(j,m){
		if(id[i][j] == 0) continue;
		if(did[id[i][j]]) continue;
		did[id[i][j]] = true;
		map<int,int> ma;
		map<int,int>::iterator it;
		for(int u = i-1; u >= 0; u--){
			if(id[u][j] > 0 && id[u][j] != id[i][j]){
				ma[id[u][j]] += 1;
			}
		}
		for(it = ma.begin(); it != ma.end(); it++){
			if((it->second)%2 == 0) continue;
			int u = it->first;
			edge[id[i][j]].push_back(u);
			edge[u].push_back(id[i][j]);
		}
	}
	int ans = 0;
	rep(i,x){
		int t = i+1;
		if(checked[t]) continue;
		int f[2];
		rep(u,2){
			rep(j,x) saw[j+1] = checked[j+1];
			f[u] = func(t,u);
		}
		ans += max(f[0],f[1]);
		rep(j,x) checked[j+1] = saw[j+1];
	}
	cout << ans << endl;
}
0