답안 #312970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312970 2020-10-14T20:34:33 Z fergonzgut21 Mecho (IOI09_mecho) C++14
73 / 100
1000 ms 9256 KB
#include <iostream>
#include <queue>
#define MAX 802
using namespace std;

struct bee
{
    short int x;
    short int y;
    int t;
    int r;
};

int N, S, sx, sy, ex, ey, B[MAX][MAX], vis[MAX][MAX][2], rilres = -1;
char A[MAX][MAX];
queue <bee> qiu;
bee temp;

void solve ()
{
    while (!qiu.empty())
    {
        temp = qiu.front();
        qiu.pop();
        temp.t++;
        if (B[temp.x - 1][temp.y] == -1 && A[temp.x - 1][temp.y] != 'T' && A[temp.x - 1][temp.y] != 'D')
        {
            B[temp.x - 1][temp.y] = temp.t;
            temp.x--;
            qiu.push(temp);
            temp.x++;
        }
        if (B[temp.x + 1][temp.y] == -1 && A[temp.x + 1][temp.y] != 'T' && A[temp.x + 1][temp.y] != 'D')
        {
            B[temp.x + 1][temp.y] = temp.t;
            temp.x++;
            qiu.push(temp);
            temp.x--;
        }
        if (B[temp.x][temp.y - 1] == -1 && A[temp.x][temp.y - 1] != 'T' && A[temp.x][temp.y - 1] != 'D')
        {
            B[temp.x][temp.y - 1] = temp.t;
            temp.y--;
            qiu.push(temp);
            temp.y++;
        }
        if (B[temp.x][temp.y + 1] == -1 && A[temp.x][temp.y + 1] != 'T' && A[temp.x][temp.y + 1] != 'D')
        {
            B[temp.x][temp.y + 1] = temp.t;
            temp.y++;
            qiu.push(temp);
            temp.y--;
        }
    }
}

int solve2(int x, int y, int t, int r)
{
    temp.x = x;
    temp.y = y;
    temp.t = t;
    temp.r = r;
    qiu.push(temp);
    while (!qiu.empty())
    {
        temp = qiu.front();
        qiu.pop();
        if (temp.t > N * N / 2)
        {
            return 0;
        }
        if (temp.x == ex && temp.y == ey)
            rilres = max(rilres,temp.r);
        if (vis[temp.x][temp.y][1] != temp.r && (temp.x != sx || temp.y != sy))
            continue;
        if (vis[temp.x][temp.y][0] != temp.t && (temp.x != sx || temp.y != sy))
            continue;
        if (temp.r + (temp.t / S) >= B[temp.x][temp.y])
            temp.r -= ((temp.r + (temp.t / S)) - B[temp.x][temp.y] + 1);
        if (temp.r <= 0 || temp.r <= rilres)
            continue;
        temp.t++;
        if (vis[temp.x + 1][temp.y][1] < temp.r && A[temp.x + 1][temp.y] != 'T')
        {
                vis[temp.x + 1][temp.y][1] = temp.r;
                vis[temp.x + 1][temp.y][0] = temp.t;
                temp.x++;
                qiu.push(temp);
                temp.x--;
        }
        if (vis[temp.x - 1][temp.y][1] < temp.r && A[temp.x - 1][temp.y] != 'T')
        {
                vis[temp.x - 1][temp.y][1] = temp.r;
                vis[temp.x - 1][temp.y][0] = temp.t;
                temp.x--;
                qiu.push(temp);
                temp.x++;
        }
        if (vis[temp.x][temp.y + 1][1] < temp.r && A[temp.x][temp.y + 1] != 'T')
        {
                vis[temp.x][temp.y + 1][1] = temp.r;
                vis[temp.x][temp.y + 1][0] = temp.t;
                temp.y++;
                qiu.push(temp);
                temp.y--;
        }
        if (vis[temp.x][temp.y - 1][1] < temp.r && A[temp.x][temp.y - 1] != 'T')
        {
                vis[temp.x][temp.y - 1][1] = temp.r;
                vis[temp.x][temp.y - 1][0] = temp.t;
                temp.y--;
                qiu.push(temp);
                temp.y++;
        }
    }
    return -1;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> S;
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
        {
            cin >> A[i][j];
            vis[i][j][1] = -1;
            vis[i][j][0] = 32700;
            B[i][j] = -1;
            if (A[i][j] == 'M')
            {
                sx = i;
                sy = j;
            }
            if (A[i][j] == 'D')
            {
                ex = i;
                ey = j;
            }
            if (A[i][j] == 'H')
            {
                temp.x = i;
                temp.y = j;
                temp.t = 0;
                B[i][j] = 0;
                qiu.push(temp);
            }
        }
    solve();
    vis[sx][sy][1] = 32700;
    vis[sx][sy][0] = 0;
    solve2(sx, sy, 0, B[sx][sy] - 1);
    cout << rilres;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 44 ms 8704 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Incorrect 1 ms 768 KB Output isn't correct
14 Correct 1 ms 896 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 0 ms 512 KB Output is correct
19 Correct 1 ms 640 KB Output is correct
20 Correct 1 ms 640 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 1 ms 640 KB Output is correct
23 Correct 1 ms 768 KB Output is correct
24 Correct 1 ms 768 KB Output is correct
25 Correct 1 ms 896 KB Output is correct
26 Correct 1 ms 896 KB Output is correct
27 Correct 1 ms 896 KB Output is correct
28 Correct 1 ms 896 KB Output is correct
29 Correct 1 ms 896 KB Output is correct
30 Correct 1 ms 896 KB Output is correct
31 Correct 1 ms 1024 KB Output is correct
32 Correct 1 ms 1024 KB Output is correct
33 Correct 6 ms 3968 KB Output is correct
34 Correct 5 ms 3968 KB Output is correct
35 Correct 100 ms 4100 KB Output is correct
36 Correct 7 ms 4480 KB Output is correct
37 Correct 6 ms 4480 KB Output is correct
38 Correct 148 ms 4600 KB Output is correct
39 Correct 10 ms 4992 KB Output is correct
40 Correct 8 ms 4992 KB Output is correct
41 Correct 214 ms 5328 KB Output is correct
42 Correct 10 ms 5504 KB Output is correct
43 Correct 9 ms 5504 KB Output is correct
44 Correct 300 ms 5784 KB Output is correct
45 Correct 12 ms 6016 KB Output is correct
46 Correct 11 ms 6016 KB Output is correct
47 Correct 389 ms 6264 KB Output is correct
48 Correct 14 ms 6656 KB Output is correct
49 Correct 12 ms 6528 KB Output is correct
50 Correct 516 ms 6924 KB Output is correct
51 Correct 16 ms 7040 KB Output is correct
52 Correct 14 ms 6912 KB Output is correct
53 Correct 656 ms 7416 KB Output is correct
54 Correct 18 ms 7680 KB Output is correct
55 Correct 16 ms 7552 KB Output is correct
56 Correct 812 ms 8276 KB Output is correct
57 Correct 20 ms 8064 KB Output is correct
58 Correct 18 ms 7936 KB Output is correct
59 Execution timed out 1041 ms 8696 KB Time limit exceeded
60 Correct 22 ms 8448 KB Output is correct
61 Correct 21 ms 8448 KB Output is correct
62 Execution timed out 1096 ms 9256 KB Time limit exceeded
63 Incorrect 38 ms 8568 KB Output isn't correct
64 Correct 48 ms 8568 KB Output is correct
65 Correct 46 ms 8568 KB Output is correct
66 Correct 44 ms 8576 KB Output is correct
67 Correct 42 ms 8448 KB Output is correct
68 Incorrect 38 ms 8576 KB Output isn't correct
69 Correct 39 ms 8576 KB Output is correct
70 Correct 35 ms 8576 KB Output is correct
71 Correct 35 ms 8700 KB Output is correct
72 Correct 32 ms 8576 KB Output is correct
73 Correct 37 ms 9088 KB Output is correct
74 Correct 51 ms 8960 KB Output is correct
75 Correct 36 ms 8952 KB Output is correct
76 Correct 36 ms 8980 KB Output is correct
77 Correct 36 ms 8960 KB Output is correct
78 Correct 38 ms 8832 KB Output is correct
79 Correct 193 ms 8832 KB Output is correct
80 Correct 49 ms 8832 KB Output is correct
81 Correct 40 ms 8832 KB Output is correct
82 Correct 67 ms 8960 KB Output is correct
83 Incorrect 40 ms 8832 KB Output isn't correct
84 Correct 70 ms 8960 KB Output is correct
85 Correct 121 ms 8944 KB Output is correct
86 Correct 142 ms 8832 KB Output is correct
87 Correct 51 ms 8832 KB Output is correct
88 Incorrect 88 ms 8804 KB Output isn't correct
89 Correct 267 ms 8824 KB Output is correct
90 Correct 41 ms 8704 KB Output is correct
91 Correct 56 ms 8704 KB Output is correct
92 Correct 43 ms 8704 KB Output is correct