Submission #1744978
Source Code Expand
#include <bits/stdc++.h> #define forn(i, n) for(int i = 0; i < (int)(n); i++) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef unsigned int ui32; const long long INFLL = 1e18; using namespace std; const int INF = 1000 * 1000 * 1000; const int MAXN = 800; char f[MAXN + 1][MAXN + 1]; int h, w, k, d[MAXN + 1][MAXN + 1], mv[4][2] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; bool valid(int x, int y) { return 1 <= x && x <= h && 1 <= y && y <= w; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> h >> w >> k; int a, b; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> f[i][j]; if (f[i][j] == 'S') a = i, b = j; d[i][j] = INF; } } queue<pair<int, int> > q; q.push({ a, b }); d[a][b] = 0; while (!q.empty()) { int x = q.front().first; int y = q.front().second; q.pop(); if (d[x][y] == k) continue; for (int i = 0; i < 4; i++) { int nx = x + mv[i][0]; int ny = y + mv[i][1]; if (valid(nx, ny) && f[nx][ny] != '#' && d[nx][ny] == INF) { d[nx][ny] = d[x][y] + 1; q.push({ nx, ny }); } } } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (d[i][j] <= k) { q.push({ i, j }); d[i][j] = 0; } } } while (!q.empty()) { int x = q.front().first; int y = q.front().second; q.pop(); for (int i = 0; i < 4; i++) { int nx = x + mv[i][0]; int ny = y + mv[i][1]; if (valid(nx, ny) && d[nx][ny] == INF) { d[nx][ny] = d[x][y] + 1; q.push({ nx, ny }); } } } int ans = INF; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (i == 1 || j == 1 || i == h || j == w) { ans = min(ans, (d[i][j] + k - 1) / k); } } } cout << 1 + ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Closed Rooms |
User | halin |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2340 Byte |
Status | AC |
Exec Time | 37 ms |
Memory | 8576 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 20 ms | 3456 KB |
in10.txt | AC | 21 ms | 3456 KB |
in11.txt | AC | 20 ms | 3456 KB |
in12.txt | AC | 21 ms | 3456 KB |
in13.txt | AC | 21 ms | 3456 KB |
in14.txt | AC | 20 ms | 3456 KB |
in15.txt | AC | 20 ms | 3456 KB |
in16.txt | AC | 21 ms | 3456 KB |
in17.txt | AC | 20 ms | 3456 KB |
in18.txt | AC | 20 ms | 3456 KB |
in19.txt | AC | 20 ms | 3456 KB |
in2.txt | AC | 21 ms | 3456 KB |
in20.txt | AC | 3 ms | 3456 KB |
in21.txt | AC | 1 ms | 256 KB |
in22.txt | AC | 1 ms | 256 KB |
in23.txt | AC | 21 ms | 3456 KB |
in24.txt | AC | 20 ms | 3456 KB |
in25.txt | AC | 20 ms | 3456 KB |
in26.txt | AC | 21 ms | 3456 KB |
in27.txt | AC | 20 ms | 3456 KB |
in28.txt | AC | 27 ms | 4480 KB |
in29.txt | AC | 35 ms | 5632 KB |
in3.txt | AC | 20 ms | 3456 KB |
in30.txt | AC | 22 ms | 3712 KB |
in31.txt | AC | 20 ms | 3456 KB |
in32.txt | AC | 20 ms | 3456 KB |
in33.txt | AC | 36 ms | 8576 KB |
in34.txt | AC | 37 ms | 8576 KB |
in35.txt | AC | 21 ms | 3456 KB |
in36.txt | AC | 20 ms | 3456 KB |
in37.txt | AC | 20 ms | 3456 KB |
in38.txt | AC | 21 ms | 3456 KB |
in39.txt | AC | 20 ms | 3456 KB |
in4.txt | AC | 21 ms | 3456 KB |
in40.txt | AC | 20 ms | 3456 KB |
in5.txt | AC | 20 ms | 3456 KB |
in6.txt | AC | 20 ms | 3456 KB |
in7.txt | AC | 21 ms | 3456 KB |
in8.txt | AC | 21 ms | 3456 KB |
in9.txt | AC | 20 ms | 3456 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |