Submission #1275726
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[105][105]; for(int i = 0; i <= h + 1; i++){ for(int j = 0; j <= w + 1; j++){ if(i == 0 || j == 0 || i == h + 1 || j == w + 1) s[i][j] = '.'; else cin >> s[i][j]; } } for(int i = 1; i <= h; i++){ for(int j = 1; j <= w; j++){ if(s[i][j] == 'X'){ if(i == 1 || j == 1 || i == h || j == w){ 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(105, vector<bool>(105, false)); int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int ans = 0; ischecked[0][0] = true; queue<pair<int, int> > qu; qu.push(make_pair(0, 0)); 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 + 1 || ny > w + 1 || 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 | 1573 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 |