結果
問題 | No.348 カゴメカゴメ |
ユーザー | 👑 はまやんはまやん |
提出日時 | 2017-04-22 06:38:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,634 bytes |
コンパイル時間 | 1,769 ms |
コンパイル使用メモリ | 177,508 KB |
実行使用メモリ | 494,184 KB |
最終ジャッジ日時 | 2023-09-28 12:40:58 |
合計ジャッジ時間 | 22,387 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 455 ms
482,900 KB |
testcase_01 | AC | 308 ms
476,996 KB |
testcase_02 | AC | 691 ms
494,184 KB |
testcase_03 | AC | 397 ms
483,044 KB |
testcase_04 | AC | 299 ms
476,916 KB |
testcase_05 | AC | 301 ms
480,836 KB |
testcase_06 | AC | 300 ms
476,872 KB |
testcase_07 | AC | 299 ms
476,916 KB |
testcase_08 | AC | 298 ms
476,840 KB |
testcase_09 | AC | 298 ms
476,912 KB |
testcase_10 | AC | 300 ms
476,868 KB |
testcase_11 | AC | 298 ms
476,932 KB |
testcase_12 | AC | 297 ms
477,452 KB |
testcase_13 | AC | 298 ms
477,172 KB |
testcase_14 | AC | 295 ms
477,028 KB |
testcase_15 | AC | 353 ms
482,860 KB |
testcase_16 | AC | 292 ms
476,852 KB |
testcase_17 | AC | 292 ms
476,864 KB |
testcase_18 | AC | 292 ms
476,844 KB |
testcase_19 | AC | 294 ms
476,852 KB |
testcase_20 | AC | 292 ms
476,956 KB |
testcase_21 | AC | 290 ms
476,972 KB |
testcase_22 | AC | 295 ms
476,856 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 | AC | 296 ms
477,348 KB |
testcase_48 | AC | 296 ms
477,272 KB |
testcase_49 | WA | - |
testcase_50 | AC | 293 ms
477,488 KB |
testcase_51 | AC | 296 ms
477,312 KB |
testcase_52 | AC | 299 ms
477,408 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) int H, W; string G[1010]; //----------------------------------------------------------------------------------- int dx[8] = { 0,1,1,1,0,-1,-1,-1 }; int dy[8] = { -1,-1,0,1,1,1,0,-1 }; int C[1010][1010], T[10101010], cnt[10101010]; set<int> E[10101010]; void makeTree() { rep(y, 0, H) rep(x, 0, W) C[y][x] = -1; int c = 0; rep(y, 0, H) rep(x, 0, W) if (C[y][x] < 0) { int d; if (G[y][x] == '.') T[c] = 0, d = 2; else T[c] = 1, d = 1; queue<int> que; que.push(y * 1010 + x); C[y][x] = c; cnt[c]++; while (!que.empty()) { int q = que.front(); que.pop(); int xx = q % 1010; int yy = q / 1010; for (int i = 0; i < 8; i += d) { int xxx = xx + dx[i]; int yyy = yy + dy[i]; if (xxx < 0 || W <= xxx) continue; if (yyy < 0 || H <= yyy) continue; if (G[y][x] != G[yyy][xxx]) continue; if (0 <= C[yyy][xxx]) continue; C[yyy][xxx] = c; cnt[c]++; que.push(yyy * 1010 + xxx); } } c++; } rep(y, 0, H) rep(x, 0, W) { rep(i, 0, 4) { int xx = x + dx[i * 2]; int yy = y + dy[i * 2]; if (xx < 0 || W <= xx) continue; if (yy < 0 || H <= yy) continue; if (C[yy][xx] == C[y][x]) continue; int ca = C[y][x]; int cb = C[yy][xx]; E[ca].insert(cb); E[cb].insert(ca); } } } //----------------------------------------------------------------------------------- pair<int, int> dfs(int cu, int pa = -1) { if (T[cu] == 0) { // ="." int a = 0, b = 0; for (int to : E[cu]) if (to != pa) { auto p = dfs(to, cu); a += p.first; b += p.second; } return { a, b }; } else { // ="x" int a = cnt[cu], b = 0; for (int to : E[cu]) if (to != pa) { auto p = dfs(to, cu); a += p.second; b += max(p.first, p.second); } return { a,b }; } } //----------------------------------------------------------------------------------- int main() { cin >> H >> W; rep(y, 1, H + 1) cin >> G[y]; rep(x, 0, W + 2) G[0] += "."; rep(y, 1, H + 1) G[y] = "." + G[y] + "."; rep(x, 0, W + 2) G[H + 1] += "."; W += 2; H += 2; makeTree(); auto p = dfs(0); int ans = max(p.first, p.second); cout << ans << endl; }