Submission #1275694
Source Code Expand
#include <cstdio> #include <iostream> #include <cmath> #include <cstring> #include <sstream> #include <algorithm> #include <cstdlib> #include <map> #include <queue> #include <utility> #include <vector> #include <set> #include <memory.h> #include <iomanip> #include <bitset> #include <list> #include <stack> #include <deque> using namespace std; #define mod 1000000007 int main() { int h, w; cin >> h >> w; char s[101][101]; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cin >> s[i][j]; } } for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(s[i][j] == 'X'){ if(i == 0 || j == 0 || i == h - 1 || j == w - 1){ cout << -1 << endl; return 0; } s[i - 1][j] = '#'; s[i][j - 1] = '#'; s[i + 1][j] = '#'; s[i][j + 1] = '#'; } } } vector<vector<bool> > ischecked(101, vector<bool>(101, false)); int sx[2] = {0, h - 1}; int sy[2] = {0, w - 1}; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int ans = 0; for(int i = 0; i < 2; i++){ for(int j = 0; j < w; j++){ if(ischecked[sx[i]][j]) continue; ischecked[sx[i]][j] = true; queue<pair<int, int> > qu; qu.push(make_pair(sx[i], j)); while(!qu.empty()){ int x = (qu.front()).first; int y = (qu.front()).second; qu.pop(); for(int k = 0; k < 4; k++){ int nx = x + dx[k]; int ny = y + dy[k]; if(nx < 0 || ny < 0 || nx >= h || ny >= w || ischecked[nx][ny]) continue; ischecked[nx][ny] = true; if(s[nx][ny] == '#') ans++; else if(s[nx][ny] == '.') qu.push(make_pair(nx, ny)); } } } } for(int i = 0; i < 2; i++){ for(int j = 0; j < h; j++){ if(ischecked[j][sy[i]]) continue; ischecked[j][sy[i]] = true; queue<pair<int, int> > qu; qu.push(make_pair(j, sy[i])); while(!qu.empty()){ int x = (qu.front()).first; int y = (qu.front()).second; qu.pop(); for(int k = 0; k < 4; k++){ int nx = x + dx[k]; int ny = y + dy[k]; if(nx < 0 || ny < 0 || nx >= h || ny >= w || ischecked[nx][ny]) continue; ischecked[nx][ny] = true; if(s[nx][ny] == '#') ans++; else if(s[nx][ny] == '.') qu.push(make_pair(nx, ny)); } } } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Fences |
User | maple |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2305 Byte |
Status | WA |
Exec Time | 2 ms |
Memory | 256 KB |
Judge Result
Set Name | All | ||||
---|---|---|---|---|---|
Score / Max Score | 0 / 150 | ||||
Status |
|
Set Name | Test Cases |
---|---|
All | 00_sample.txt, 01_sample.txt, 02_sample.txt, 10_rand_00.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 10_rand_06.txt, 10_rand_07.txt, 10_rand_08.txt, 11_hashi_00.txt, 11_hashi_01.txt, 11_hashi_02.txt, 12_rect_00.txt, 12_rect_01.txt, 12_rect_02.txt, 99_all_one.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample.txt | AC | 1 ms | 256 KB |
01_sample.txt | AC | 1 ms | 256 KB |
02_sample.txt | AC | 1 ms | 256 KB |
10_rand_00.txt | WA | 1 ms | 256 KB |
10_rand_01.txt | WA | 1 ms | 256 KB |
10_rand_02.txt | WA | 1 ms | 256 KB |
10_rand_03.txt | WA | 1 ms | 256 KB |
10_rand_04.txt | WA | 2 ms | 256 KB |
10_rand_05.txt | WA | 2 ms | 256 KB |
10_rand_06.txt | AC | 1 ms | 256 KB |
10_rand_07.txt | WA | 2 ms | 256 KB |
10_rand_08.txt | WA | 2 ms | 256 KB |
11_hashi_00.txt | AC | 1 ms | 256 KB |
11_hashi_01.txt | AC | 1 ms | 256 KB |
11_hashi_02.txt | AC | 1 ms | 256 KB |
12_rect_00.txt | WA | 2 ms | 256 KB |
12_rect_01.txt | WA | 1 ms | 256 KB |
12_rect_02.txt | WA | 2 ms | 256 KB |
99_all_one.txt | AC | 2 ms | 256 KB |