結果

問題 No.348 カゴメカゴメ
ユーザー gasingasin
提出日時 2016-03-05 14:16:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,124 bytes
コンパイル時間 1,972 ms
コンパイル使用メモリ 182,920 KB
実行使用メモリ 62,784 KB
最終ジャッジ日時 2023-10-24 19:54:01
合計ジャッジ時間 5,521 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
map<int,bool> saw;
int num[1000000];
int n, m;
int x = 0;
vector<int> edge[1000000];
vector<int> gr[1000000];

int func(int a, int type){
	saw[a] = true;
	checked[a] = true;
	int ret = 0;
	if(type == 0) ret += num[a];
	rep(i,edge[a].size()){
		int e = edge[a][i];
		if(saw[e]) continue;
		ret += max(func(e,0),func(e,1));
	}
	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;
	}
	int y = 0;
	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, ma2, ok;
		map<int,int>::iterator it;
		queue<int> qu;
		for(int u = i-1; u >= 0; u--){
			if(id[u][j] > 0 && id[u][j] != id[i][j]){
				ma[id[u][j]] += 1;
				qu.push(id[u][j]);
			}
		}
		for(int u = j-1; u >= 0; u--){
			if(id[i][u] > 0 && id[i][u] != id[i][j]){
				ma2[id[i][u]] += 1;
			}
		}
		while(true){
			if(qu.size() == 0) break;
			int q = qu.front();
			qu.pop();
			if(ma[q]%2 == 0) continue;
			if(ma2[q]%2 == 0) continue;
			edge[id[i][j]].push_back(q);
			edge[q].push_back(id[i][j]);
			break;
		}
		y++;
	}
	return 0;
	int ans = 0;
	rep(i,x){
		int t = i+1;
		if(checked[t]) continue;
		int f[2];
		rep(u,2){
			f[u] = func(t,u);
		}
		ans += max(f[0],f[1]);
		saw.clear();
	}
	cout << ans << endl;
}
0