結果
問題 | No.348 カゴメカゴメ |
ユーザー | Kmcode1 |
提出日時 | 2016-02-26 23:46:03 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 218 ms / 2,000 ms |
コード長 | 4,320 bytes |
コンパイル時間 | 1,452 ms |
コンパイル使用メモリ | 118,224 KB |
実行使用メモリ | 52,200 KB |
最終ジャッジ日時 | 2024-09-23 03:09:06 |
合計ジャッジ時間 | 5,595 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 98 ms
36,224 KB |
testcase_01 | AC | 11 ms
27,904 KB |
testcase_02 | AC | 218 ms
52,200 KB |
testcase_03 | AC | 141 ms
39,296 KB |
testcase_04 | AC | 11 ms
27,520 KB |
testcase_05 | AC | 12 ms
29,312 KB |
testcase_06 | AC | 11 ms
27,776 KB |
testcase_07 | AC | 12 ms
27,648 KB |
testcase_08 | AC | 11 ms
27,520 KB |
testcase_09 | AC | 11 ms
27,904 KB |
testcase_10 | AC | 12 ms
27,648 KB |
testcase_11 | AC | 11 ms
27,648 KB |
testcase_12 | AC | 14 ms
28,416 KB |
testcase_13 | AC | 12 ms
28,032 KB |
testcase_14 | AC | 12 ms
27,776 KB |
testcase_15 | AC | 65 ms
29,568 KB |
testcase_16 | AC | 11 ms
27,648 KB |
testcase_17 | AC | 12 ms
27,520 KB |
testcase_18 | AC | 11 ms
27,520 KB |
testcase_19 | AC | 11 ms
27,392 KB |
testcase_20 | AC | 12 ms
27,776 KB |
testcase_21 | AC | 12 ms
27,520 KB |
testcase_22 | AC | 12 ms
27,648 KB |
testcase_23 | AC | 138 ms
38,996 KB |
testcase_24 | AC | 136 ms
39,056 KB |
testcase_25 | AC | 138 ms
39,080 KB |
testcase_26 | AC | 138 ms
39,148 KB |
testcase_27 | AC | 135 ms
39,092 KB |
testcase_28 | AC | 138 ms
38,968 KB |
testcase_29 | AC | 138 ms
39,028 KB |
testcase_30 | AC | 137 ms
39,160 KB |
testcase_31 | AC | 137 ms
39,028 KB |
testcase_32 | AC | 137 ms
39,172 KB |
testcase_33 | AC | 22 ms
29,312 KB |
testcase_34 | AC | 22 ms
29,440 KB |
testcase_35 | AC | 22 ms
29,312 KB |
testcase_36 | AC | 22 ms
29,420 KB |
testcase_37 | AC | 22 ms
29,544 KB |
testcase_38 | AC | 22 ms
29,324 KB |
testcase_39 | AC | 22 ms
29,312 KB |
testcase_40 | AC | 22 ms
29,184 KB |
testcase_41 | AC | 22 ms
29,420 KB |
testcase_42 | AC | 23 ms
29,412 KB |
testcase_43 | AC | 14 ms
28,416 KB |
testcase_44 | AC | 13 ms
28,416 KB |
testcase_45 | AC | 13 ms
28,288 KB |
testcase_46 | AC | 14 ms
28,288 KB |
testcase_47 | AC | 13 ms
28,416 KB |
testcase_48 | AC | 14 ms
28,416 KB |
testcase_49 | AC | 13 ms
28,416 KB |
testcase_50 | AC | 14 ms
28,288 KB |
testcase_51 | AC | 14 ms
28,288 KB |
testcase_52 | AC | 14 ms
28,288 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:202:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 202 | scanf("%s", room[i]); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<vector> #include<list> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<sstream> #include<fstream> #include<iomanip> #include<ctime> #include<complex> #include<functional> #include<climits> #include<cassert> #include<iterator> using namespace std; #define MAX 1012 int n; int m; char room[MAX][MAX]; int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }; int dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 }; struct st{ vector < pair<int, int> > v; }; vector<st> v; bool use[MAX][MAX]; int deg[MAX*MAX]; int id[MAX][MAX]; bool valid(int x, int y){ if (x < 0 || y < 0 || x >= n || y >= m){ return false; } if (use[x][y]){ return false; } if (room[x][y] == '.'){ return false; } return true; } inline void dfs(int a, int b,int ii){ use[a][b] = true; id[a][b] = ii; v[ii].v.push_back(make_pair(a, b)); for (int i = 0; i < 8; i++){ if (valid(a + dx[i], b + dy[i])){ dfs(a + dx[i], b + dy[i],ii); } } } bool done[MAX*MAX]; vector<int> g[MAX*MAX]; bool s[MAX][MAX]; int dxx[] = { 0, 0, 1, -1 }; int dyy[] = { 1, -1, 0, 0 }; bool vv(int a, int b){ if (a < 0 || b < 0 || a >= n || b >= m){ return false; } if (room[a][b] == '.'){ return true; } return false; } bool v2(int a, int b){ if (a < 0 || b < 0 || a >= n || b >= m){ return false; } return true; } vector<int> bfs(int a, int b){ vector<int> r; s[a][b] = true; queue<pair<int, int> > q; q.push(make_pair(a, b)); while (!q.empty()){ a = q.front().first; b = q.front().second; q.pop(); for (int i = 0; i < 4; i++){ int aa = a + dxx[i]; int bb = b + dyy[i]; if (vv(aa, bb)){ if (s[aa][bb] == false){ s[aa][bb] = true; q.push(make_pair(aa, bb)); } } else{ if (v2(aa, bb)){ r.push_back(id[aa][bb]); } } } for (int i = 0; i < 8; i++){ if (dx[i] == 0 || dy[i] == 0){ continue; } if (vv(a + dx[i], b + dy[i])){ if (v2(a, b + dy[i]) && vv(a, b + dy[i]) == false){ if (v2(a + dx[i], b) && vv(a + dx[i], b) == false){ r.push_back(id[a + dx[i]][b]); continue; } } if (s[a + dx[i]][b + dy[i]] == false){ q.push(make_pair(a + dx[i], b + dy[i])); s[a + dx[i]][b + dy[i]] = true; } } else{ if (v2(a + dx[i], b + dy[i])){ r.push_back(id[a + dx[i]][b + dy[i]]); } } } } sort(r.begin(), r.end()); r.erase(unique(r.begin(), r.end()), r.end()); return r; } inline void f(int b){ done[b] = true; set<int> vv; for (int i = 0; i < v[b].v.size(); i++){ for (int j = 0; j < 8; j++){ int xx = v[b].v[i].first + dx[j]; int yy = v[b].v[i].second + dy[j]; if (xx >= 0 && yy >= 0 && xx < n&&yy < m){ if (room[xx][yy] == '.'){ if (s[xx][yy] == false){ vector<int> rr = bfs(xx, yy); for (int ii = 0; ii < rr.size(); ii++){ vv.insert(rr[ii]); } } } } } } if (vv.count(b)){ vv.erase(b); } for (auto it = vv.begin();it!= vv.end(); it++){ g[b].push_back((*it)); } vv.clear(); for (int i = 0; i < g[b].size(); i++){ f(g[b][i]); deg[g[b][i]]++; } } int dp[MAX*MAX][2]; inline void d(int b){ dp[b][0] = v[b].v.size(); for (int i = 0; i < g[b].size(); i++){ int id = g[b][i]; d(id); dp[b][1] += max(dp[id][0], dp[id][1]); dp[b][0] += dp[id][1]; } } int main(){ cin >> n >> m; for (int i = 0; i < n; i++){ scanf("%s", room[i]); } for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ if (valid(i, j)){ v.push_back(st()); dfs(i, j, v.size() - 1); } } } for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ if (i == 0 || j == 0 || i == n - 1 || j == m - 1){ if (room[i][j] == '.'){ if (s[i][j] == false){ bfs(i, j); } } } } } for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ if (room[i][j] == 'x'){ if (done[id[i][j]] == false){ f(id[i][j]); } } } } int ans = 0; for (int i = 0; i < v.size(); i++){ if (deg[i] == 0){ d(i); ans += max(dp[i][0], dp[i][1]); } } cout << ans << endl; return 0; }