Submission #1553812


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
int H, W, K;
int MAP[1000][1000];
int x, y, vis[1000][1000];
int ans = 2147483647;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
struct PR {
    int x, y, now;
    PR() {x = y = now = 0;}
    PR(int _x, int _y, int _now) {x = _x, y = _y, now = _now;}
};
bool check(int x, int y) {
    if (x < 0 || x > H) return 0;
    if (y < 0 || y > W) return 0;
    if (MAP[x][y]) return 0;
    return 1;
}
int main() {
    cin >> H >> W >> K;
    for (int i = 1; i <= H; i ++) {
        string s;
        cin >> s;
        for (int j = 1; j <= W; j ++) {
            if (s[j - 1] == '#') MAP[i][j] = 1;
            else {
                MAP[i][j] = 0;
                if (s[j - 1] == 'S') x = i, y = j; 
            }
        }
    }
    queue<PR> Q; Q.push((PR){x, y, 0});
    while (!Q.empty()) {
        PR tmp = Q.front(); Q.pop();
        if (tmp.now > K) continue;
        if (vis[tmp.x][tmp.y] <= tmp.now && vis[tmp.x][tmp.y] != 0) continue;
        vis[tmp.x][tmp.y] = tmp.now;
		int num = min(min(H - tmp.x, W - tmp.y), min(tmp.x - 1, tmp.y - 1));
		num = (num + K - 1) / K;
		if (num + 1 > ans) continue;
		ans = min(ans, num + 1);
        for (int i = 0; i < 4; i ++) {
            if (check(tmp.x + dx[i], tmp.y + dy[i])) Q.push((PR){tmp.x + dx[i], tmp.y + dy[i], tmp.now + 1});
        }
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task A - Cookie Exchanges
User xc01
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1449 Byte
Status RE
Exec Time 2103 ms
Memory 6016 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 1
WA × 2
AC × 3
WA × 4
TLE × 9
RE × 1
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in2.txt, in3.txt, in4.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 TLE 2103 ms 6016 KB
in10.txt AC 2 ms 2304 KB
in11.txt TLE 2103 ms 6016 KB
in2.txt TLE 2103 ms 6016 KB
in3.txt RE 1764 ms 6016 KB
in4.txt TLE 2103 ms 6016 KB
in5.txt TLE 2103 ms 6016 KB
in6.txt TLE 2103 ms 6016 KB
in7.txt TLE 2103 ms 6016 KB
in8.txt TLE 2103 ms 6016 KB
in9.txt TLE 2103 ms 6016 KB
sample1.txt WA 2 ms 2304 KB
sample2.txt WA 2 ms 2304 KB
sample3.txt AC 4 ms 6016 KB