結果
| 問題 |
No.348 カゴメカゴメ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-02 13:33:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,954 bytes |
| コンパイル時間 | 1,356 ms |
| コンパイル使用メモリ | 117,316 KB |
| 実行使用メモリ | 11,904 KB |
| 最終ジャッジ日時 | 2024-10-10 23:52:57 |
| 合計ジャッジ時間 | 5,179 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 WA * 25 |
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[] = {1, 0, -1, 0, -1, 1, -1, 1};
pair<int, int> solve2(int sy, int sx);
int h, w;
vector<string> s;
vector<vector<bool> > check;
pair<int, int> solve1(int sy, int sx)
{
queue<pair<int, int> > q, select;
q.push(make_pair(sy, sx));
check[sy][sx] = true;
while(!q.empty()){
int y = q.front().first;
int x = q.front().second;
q.pop();
for(int i=0; i<4; ++i){
int y2 = y + dy[i];
int x2 = x + dx[i];
if(!(0 <= y2 && y2 < h && 0 <= x2 && x2 < w) || check[y2][x2])
continue;
if(s[y2][x2] == '.'){
check[y2][x2] = true;
q.push(make_pair(y2, x2));
}
else{
select.push(make_pair(y2, x2));
}
}
}
pair<int, int> ans(0, 0);
while(!select.empty()){
int y = select.front().first;
int x = select.front().second;
select.pop();
if(!check[y][x]){
pair<int, int> p = solve2(y, x);
ans.first += p.first;
ans.second += p.second;
}
}
return ans;
}
pair<int, int> solve2(int sy, int sx)
{
queue<pair<int, int> > q;
q.push(make_pair(sy, sx));
check[sy][sx] = true;
int cnt = 1;
while(!q.empty()){
int y = q.front().first;
int x = q.front().second;
q.pop();
for(int i=0; i<8; ++i){
int y2 = y + dy[i];
int x2 = x + dx[i];
if(check[y2][x2])
continue;
if(s[y2][x2] == 'x'){
check[y2][x2] = true;
q.push(make_pair(y2, x2));
++ cnt;
}
}
}
for(int i=0; i<4; ++i){
int y2 = sy + dy[i];
int x2 = sx + dx[i];
if(check[y2][x2])
continue;
if(s[y2][x2] == '.'){
pair<int, int> p = solve1(y2, x2);
swap(p.first, p.second);
p.second = max(p.second, p.first);
p.first += cnt;
return p;
}
}
return make_pair(cnt, 0);
}
int main()
{
cin >> h >> w;
h += 2;
w += 2;
s.assign(h, string(w, '.'));
for(int y=1; y<h-1; ++y){
for(int x=1; x<w-1; ++x){
cin >> s[y][x];
}
}
check.assign(h, vector<bool>(w, false));
pair<int, int> ans = solve1(0, 0);
cout << max(ans.first, ans.second) << endl;
return 0;
}