Submission #4065174
Source Code Expand
#include<stack>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
putchar('\n');
}
const int dy[] = {0,1,0,-1};
const int dx[] = {1,0,-1,0};
int N, M, K;
int si, sj;
char F[811][811];
int W[811][811];
int D[811][811];
bool in(int y, int x) {
return 0 <= y && y < N && 0 <= x && x < M;
}
void MAIN() {
scanf("%d%d%d", &N, &M, &K);
REP (i, N) scanf("%s", F[i]);
REP (i, N) REP (j, M) if (F[i][j] == 'S') {
si = i;
sj = j;
}
memset(W, 0x3f, sizeof W);
const int INF = W[0][0];
stack<pair<int, int> > cur, nxt;
W[si][sj] = 0;
cur.emplace(si, sj);
while (1) {
if (cur.empty()) swap(cur, nxt);
if (cur.empty()) break;
int y = cur.top().first;
int x = cur.top().second;
cur.pop();
REP (d, 4) {
int yy = y + dy[d];
int xx = x + dx[d];
if (in(yy, xx) && W[yy][xx] == INF) {
if (F[yy][xx] == '.') {
W[yy][xx] = W[y][x];
cur.emplace(yy, xx);
} else {
W[yy][xx] = W[y][x] + 1;
nxt.emplace(yy, xx);
}
}
}
}
memset(D, 0x3f, sizeof D);
D[si][sj] = 0;
cur.emplace(si, sj);
stack<pair<int, int> > nnxt;
nnxt.emplace(si, sj);
int ans = 1;
while (1) {
bool ok = false;
REP (i, K) {
if (cur.empty()) break;
while (!cur.empty()) {
int y = cur.top().first;
int x = cur.top().second;
cur.pop();
REP (d, 4) {
int yy = y + dy[d];
int xx = x + dx[d];
if (in(yy, xx) && D[yy][xx] == INF && W[yy][xx] <= (ans - 1) * K) {
D[yy][xx] = D[y][x] + 1;
nxt.emplace(yy, xx);
nnxt.emplace(yy, xx);
if (yy == 0 || yy == N-1 || xx == 0 || xx == M-1) ok = true;
}
}
}
swap(cur, nxt);
}
while (!cur.empty()) cur.pop();
swap(cur, nnxt);
if (ok) {
break;
} else {
ans++;
}
}
printf("%d\n", ans);
}
int main() {
int TC = 1;
// scanf("%d", &TC);
REP (tc, TC) MAIN();
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Closed Rooms |
User |
natsugiri |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
2669 Byte |
Status |
AC |
Exec Time |
43 ms |
Memory |
11264 KB |
Compile Error
./Main.cpp: In function ‘void MAIN()’:
./Main.cpp:38:32: 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:39:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP (i, N) scanf("%s", F[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 |
24 ms |
6016 KB |
in10.txt |
AC |
24 ms |
6144 KB |
in11.txt |
AC |
24 ms |
6016 KB |
in12.txt |
AC |
25 ms |
6144 KB |
in13.txt |
AC |
27 ms |
6272 KB |
in14.txt |
AC |
27 ms |
6272 KB |
in15.txt |
AC |
25 ms |
6144 KB |
in16.txt |
AC |
25 ms |
6144 KB |
in17.txt |
AC |
25 ms |
6144 KB |
in18.txt |
AC |
38 ms |
6656 KB |
in19.txt |
AC |
25 ms |
6144 KB |
in2.txt |
AC |
43 ms |
11008 KB |
in20.txt |
AC |
4 ms |
6016 KB |
in21.txt |
AC |
3 ms |
5376 KB |
in22.txt |
AC |
3 ms |
5376 KB |
in23.txt |
AC |
24 ms |
6016 KB |
in24.txt |
AC |
28 ms |
6400 KB |
in25.txt |
AC |
24 ms |
6016 KB |
in26.txt |
AC |
35 ms |
7352 KB |
in27.txt |
AC |
26 ms |
7416 KB |
in28.txt |
AC |
30 ms |
7344 KB |
in29.txt |
AC |
39 ms |
8264 KB |
in3.txt |
AC |
27 ms |
6144 KB |
in30.txt |
AC |
34 ms |
8112 KB |
in31.txt |
AC |
25 ms |
7444 KB |
in32.txt |
AC |
24 ms |
7352 KB |
in33.txt |
AC |
39 ms |
11156 KB |
in34.txt |
AC |
39 ms |
11180 KB |
in35.txt |
AC |
29 ms |
8104 KB |
in36.txt |
AC |
42 ms |
11264 KB |
in37.txt |
AC |
25 ms |
6144 KB |
in38.txt |
AC |
26 ms |
6016 KB |
in39.txt |
AC |
22 ms |
8448 KB |
in4.txt |
AC |
43 ms |
11264 KB |
in40.txt |
AC |
21 ms |
8448 KB |
in5.txt |
AC |
42 ms |
11264 KB |
in6.txt |
AC |
27 ms |
6144 KB |
in7.txt |
AC |
24 ms |
6144 KB |
in8.txt |
AC |
43 ms |
11008 KB |
in9.txt |
AC |
25 ms |
6144 KB |
sample1.txt |
AC |
3 ms |
5376 KB |
sample2.txt |
AC |
3 ms |
5376 KB |
sample3.txt |
AC |
3 ms |
5376 KB |