Submission #1263486
Source Code Expand
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <functional>
using namespace std;
#define F first
#define S second
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << ": "; for (auto& xxxx: a) cerr << xxxx << " "; cerr << endl;
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))
#define equal equalll
#define less lesss
typedef long double dbl;
typedef long long ll;
const int N = 888;
const ll INF = 1.01e9;
typedef vector<int> vi;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
char s[N][N];
int main(){
#ifdef HOME
assert(freopen("in", "r", stdin));
#endif
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
int sx = -1;
int sy = -1;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
if (s[i][j] == 'S') {
sx = i;
sy = j;
}
}
queue<pair<int,int>> q;
q.push({sx, sy});
vector<vector<int>> dist(n, vector<int>(m, INF));
dist[sx][sy] = 0;
while (!q.empty()) {
int x = q.front().F;
int y = q.front().S;
q.pop();
for (int i = 0; i < 4; i++) {
int xx = x + dx[i];
int yy = y + dy[i];
if (0 <= xx && xx < n && 0 <= yy && yy < m && s[xx][yy] == '.' && dist[xx][yy] > dist[x][y] + 1) {
dist[xx][yy] = dist[x][y] + 1;
q.push({xx, yy});
}
}
}
int best = INF;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (dist[i][j] <= k) {
best = min(best, i);
best = min(best, j);
best = min(best, n - i - 1);
best = min(best, m - j - 1);
}
if (sx == 0 || sy == 0 || sx == n - 1 || sy == m - 1) {
puts("0");
}
else {
printf("%d\n", 1 + (best + k - 1) / k);
}
#ifdef HOME
epr("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Closed Rooms |
User |
Belonogov |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
2747 Byte |
Status |
AC |
Exec Time |
24 ms |
Memory |
3584 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:50:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &m, &k);
^
./Main.cpp:52:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s[i]);
^
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 |
5 ms |
3456 KB |
in10.txt |
AC |
5 ms |
3456 KB |
in11.txt |
AC |
5 ms |
3456 KB |
in12.txt |
AC |
5 ms |
3456 KB |
in13.txt |
AC |
5 ms |
3456 KB |
in14.txt |
AC |
5 ms |
3456 KB |
in15.txt |
AC |
5 ms |
3456 KB |
in16.txt |
AC |
5 ms |
3456 KB |
in17.txt |
AC |
5 ms |
3456 KB |
in18.txt |
AC |
5 ms |
3456 KB |
in19.txt |
AC |
5 ms |
3456 KB |
in2.txt |
AC |
5 ms |
3456 KB |
in20.txt |
AC |
2 ms |
1024 KB |
in21.txt |
AC |
1 ms |
256 KB |
in22.txt |
AC |
1 ms |
256 KB |
in23.txt |
AC |
5 ms |
3456 KB |
in24.txt |
AC |
5 ms |
3456 KB |
in25.txt |
AC |
5 ms |
3456 KB |
in26.txt |
AC |
23 ms |
3456 KB |
in27.txt |
AC |
22 ms |
3456 KB |
in28.txt |
AC |
24 ms |
3584 KB |
in29.txt |
AC |
23 ms |
3456 KB |
in3.txt |
AC |
5 ms |
3456 KB |
in30.txt |
AC |
23 ms |
3456 KB |
in31.txt |
AC |
22 ms |
3456 KB |
in32.txt |
AC |
22 ms |
3456 KB |
in33.txt |
AC |
21 ms |
3456 KB |
in34.txt |
AC |
23 ms |
3456 KB |
in35.txt |
AC |
21 ms |
3456 KB |
in36.txt |
AC |
5 ms |
3456 KB |
in37.txt |
AC |
5 ms |
3456 KB |
in38.txt |
AC |
5 ms |
3456 KB |
in39.txt |
AC |
21 ms |
3456 KB |
in4.txt |
AC |
5 ms |
3456 KB |
in40.txt |
AC |
20 ms |
3456 KB |
in5.txt |
AC |
5 ms |
3456 KB |
in6.txt |
AC |
5 ms |
3456 KB |
in7.txt |
AC |
5 ms |
3456 KB |
in8.txt |
AC |
5 ms |
3456 KB |
in9.txt |
AC |
5 ms |
3456 KB |
sample1.txt |
AC |
1 ms |
256 KB |
sample2.txt |
AC |
1 ms |
256 KB |
sample3.txt |
AC |
1 ms |
256 KB |