Submission #312936

# Submission time Handle Problem Language Result Execution time Memory
312936 2020-10-14T19:04:53 Z fergonzgut21 Mecho (IOI09_mecho) C++14
17 / 100
1000 ms 7808 KB
#include <iostream>
#include <queue>
#define MAX 805
using namespace std;

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

int N, S, sx, sy, ex, ey, B[MAX][MAX], vis[MAX][MAX];
char A[MAX][MAX];
queue <bee> qiu, qiu2;
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;
    qiu2.push(temp);
    while (!qiu2.empty())
    {
        temp = qiu2.front();
        qiu2.pop();
        if (temp.x == ex && temp.y == ey)
            return temp.r;
        //cout << temp.x << " " << temp.y << " " << temp.t << " " << temp.r << endl;
        if (temp.r + (temp.t / S) >= B[x][y])
            temp.r -= (temp.r + (temp.t / S)) - B[x][y] + 1;
        if (temp.r < 0)
            continue;
        temp.t++;
        if (vis[temp.x + 1][temp.y] > temp.r && A[temp.x + 1][temp.y] != 'T')
        {
            vis[temp.x + 1][temp.y] = temp.r;
            temp.x++;
            qiu2.push(temp);
            temp.x--;
        }
        if (vis[temp.x - 1][temp.y] > temp.r && A[temp.x - 1][temp.y] != 'T')
        {
            vis[temp.x - 1][temp.y] = temp.r;
            temp.x--;
            qiu2.push(temp);
            temp.x++;
        }
        if (vis[temp.x][temp.y + 1] > temp.r && A[temp.x][temp.y + 1] != 'T')
        {
            vis[temp.x][temp.y + 1] = temp.r;
            temp.y++;
            qiu2.push(temp);
            temp.y--;
        }
        if (vis[temp.x][temp.y - 1] > temp.r && A[temp.x][temp.y - 1] != 'T')
        {
            vis[temp.x][temp.y - 1] = temp.r;
            temp.y--;
            qiu2.push(temp);
            temp.y++;
        }
    }
    return -1;
}

int main()
{
    cin >> N >> S;
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
        {
            cin >> A[i][j];
            vis[i][j] =1073741822;
            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();
    /*cout << endl;
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            cout << B[i][j] << " ";
        }
        cout << endl;
    }*/
    vis[sx][sy] = 0;
    cout << solve2(sx, sy, 0, B[sx][sy] - 1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Correct 0 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Incorrect 188 ms 6648 KB Output isn't correct
8 Correct 1 ms 512 KB Output is correct
9 Incorrect 0 ms 384 KB Output isn't correct
10 Incorrect 1 ms 384 KB Output isn't correct
11 Incorrect 1 ms 384 KB Output isn't correct
12 Correct 1 ms 768 KB Output is correct
13 Incorrect 1 ms 640 KB Output isn't correct
14 Incorrect 1 ms 768 KB Output isn't correct
15 Incorrect 1 ms 512 KB Output isn't correct
16 Correct 1 ms 512 KB Output is correct
17 Incorrect 1 ms 512 KB Output isn't correct
18 Correct 1 ms 512 KB Output is correct
19 Incorrect 1 ms 512 KB Output isn't correct
20 Correct 1 ms 512 KB Output is correct
21 Incorrect 1 ms 640 KB Output isn't correct
22 Correct 1 ms 640 KB Output is correct
23 Incorrect 1 ms 640 KB Output isn't correct
24 Correct 1 ms 640 KB Output is correct
25 Incorrect 1 ms 768 KB Output isn't correct
26 Correct 1 ms 768 KB Output is correct
27 Incorrect 1 ms 768 KB Output isn't correct
28 Correct 1 ms 768 KB Output is correct
29 Incorrect 1 ms 896 KB Output isn't correct
30 Correct 1 ms 768 KB Output is correct
31 Incorrect 1 ms 896 KB Output isn't correct
32 Correct 1 ms 896 KB Output is correct
33 Incorrect 13 ms 2816 KB Output isn't correct
34 Correct 12 ms 2816 KB Output is correct
35 Incorrect 15 ms 2816 KB Output isn't correct
36 Incorrect 17 ms 3232 KB Output isn't correct
37 Correct 16 ms 3328 KB Output is correct
38 Incorrect 18 ms 3200 KB Output isn't correct
39 Incorrect 21 ms 3584 KB Output isn't correct
40 Correct 20 ms 3584 KB Output is correct
41 Incorrect 23 ms 3584 KB Output isn't correct
42 Incorrect 25 ms 3840 KB Output isn't correct
43 Correct 26 ms 3832 KB Output is correct
44 Incorrect 28 ms 3840 KB Output isn't correct
45 Incorrect 30 ms 4224 KB Output isn't correct
46 Correct 30 ms 4216 KB Output is correct
47 Incorrect 34 ms 4224 KB Output isn't correct
48 Incorrect 35 ms 4600 KB Output isn't correct
49 Correct 34 ms 4600 KB Output is correct
50 Incorrect 42 ms 4608 KB Output isn't correct
51 Incorrect 41 ms 4984 KB Output isn't correct
52 Correct 40 ms 4984 KB Output is correct
53 Incorrect 48 ms 4984 KB Output isn't correct
54 Incorrect 49 ms 5240 KB Output isn't correct
55 Correct 46 ms 5240 KB Output is correct
56 Incorrect 55 ms 5372 KB Output isn't correct
57 Incorrect 56 ms 5752 KB Output isn't correct
58 Correct 54 ms 5624 KB Output is correct
59 Incorrect 64 ms 5752 KB Output isn't correct
60 Incorrect 61 ms 6008 KB Output isn't correct
61 Correct 59 ms 6008 KB Output is correct
62 Incorrect 76 ms 6008 KB Output isn't correct
63 Execution timed out 1085 ms 7160 KB Time limit exceeded
64 Incorrect 96 ms 6008 KB Output isn't correct
65 Execution timed out 1089 ms 7224 KB Time limit exceeded
66 Execution timed out 1095 ms 7420 KB Time limit exceeded
67 Execution timed out 1042 ms 7036 KB Time limit exceeded
68 Incorrect 413 ms 6264 KB Output isn't correct
69 Incorrect 133 ms 6136 KB Output isn't correct
70 Incorrect 822 ms 6732 KB Output isn't correct
71 Execution timed out 1033 ms 6988 KB Time limit exceeded
72 Incorrect 73 ms 6136 KB Output isn't correct
73 Incorrect 68 ms 6520 KB Output isn't correct
74 Incorrect 79 ms 6520 KB Output isn't correct
75 Incorrect 378 ms 7204 KB Output isn't correct
76 Incorrect 533 ms 7808 KB Output isn't correct
77 Incorrect 248 ms 6648 KB Output isn't correct
78 Incorrect 343 ms 7044 KB Output isn't correct
79 Incorrect 80 ms 6520 KB Output isn't correct
80 Incorrect 341 ms 6996 KB Output isn't correct
81 Incorrect 452 ms 7464 KB Output isn't correct
82 Incorrect 218 ms 6520 KB Output isn't correct
83 Incorrect 423 ms 7116 KB Output isn't correct
84 Incorrect 83 ms 6396 KB Output isn't correct
85 Incorrect 267 ms 6700 KB Output isn't correct
86 Incorrect 346 ms 6844 KB Output isn't correct
87 Incorrect 183 ms 6392 KB Output isn't correct
88 Incorrect 290 ms 6768 KB Output isn't correct
89 Incorrect 83 ms 6264 KB Output isn't correct
90 Incorrect 195 ms 6348 KB Output isn't correct
91 Incorrect 140 ms 6388 KB Output isn't correct
92 Incorrect 241 ms 6476 KB Output isn't correct