답안 #886350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886350 2023-12-11T22:56:40 Z Juanchoki Mecho (IOI09_mecho) C++14
9 / 100
1000 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
struct tpos
{
    int i, j, t;
};
bool operator < (const tpos &a, const tpos &b)
{
    if (a.i == b.i) return a.j < b.j;
    return a.i < b.i;
}
char mat[801][801];
char aux[801][801];
int iini, jini;
int n, s; 
vector<tpos> abejas;
bool verifica (int i, int j)
{
    if (i < 0 || j < 0 || i >= n || j >= n)
        return 0;
    return 1;
}
int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
void expande_abejas(queue<tpos> &abeja, int t, vector<vector<bool>> &visi)
{
    tpos temp;
    int ti, tj;
    while (!abeja.empty())
    {
        temp = abeja.front(); 
        if (temp.t == t) return;
        abeja.pop();
        visi[temp.i][temp.j] = 1;
        for (int k = 0; k < 4; k++) 
        {
            ti = temp.i + di[k], tj = temp.j + dj[k]; 
            if (!verifica(ti, tj)) continue;
            if (visi[ti][tj])  continue;
            abeja.push({ti, tj, temp.t + 1});
        }
    }
}
bool sepuede(int t)
{
    vector<vector<bool>>visi(n, vector<bool>(n, 0)); //ya lo invadieron las abejas?
    queue<tpos> mecho;
    queue<tpos> abeja;
    mecho.push({iini, jini, 0});
    for (int i = 0, l = abejas.size(); i < l; i++)
        abeja.push({abejas[i].i, abejas[i].j, 0});

    tpos temp;
    int ti, tj;

    while (!abeja.empty())
    {
        temp = abeja.front(); 
        if (temp.t > t) break;
        abeja.pop();
        visi[temp.i][temp.j] = 1;
        for (int k = 0; k < 4; k++) 
        {
            ti = temp.i + di[k], tj = temp.j + dj[k]; 
            if (!verifica(ti, tj)) continue;
            if (visi[ti][tj])  continue;
            abeja.push({ti, tj, temp.t + 1});
        }
    }

    //vector<vector<bool>> yo (n, vector<bool>(n, 0)); //posiciones que ha ocupado el mecho
    bool llego = 0;
    int primero = s;
    while (!mecho.empty())
    {
        temp = mecho.front(); mecho.pop();
        if (visi[temp.i][temp.j]) continue;
        if (temp.t > primero)
        {   
            expande_abejas(abeja, t+(primero)/s, visi);
            primero+= s;
        } 
        if (visi[temp.i][temp.j]) return 0;
        if (mat[temp.i][temp.j] == 'D') return 1;

        for (int k = 0; k < 4; k++) 
        {
            ti = temp.i + di[k], tj = temp.j + dj[k]; 
            if (!verifica(ti, tj)) continue;
            if (visi[ti][tj])  continue;
            mecho.push({ti, tj, temp.t + 1});
        }
    }
    return 0;
}
int main ()
{
    cin >> n >> s;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            {
                cin >> mat[i][j];
                aux[i][j] = mat[i][j];
                if (mat[i][j] == 'M')   
                    {
                        iini = i;
                        jini = j;
                        continue;
                    }
                if (mat[i][j] == 'H')
                    abejas.pb({i, j, 0});
            }

    int l = 0, r = (1<<11), resp = -1;

    while (l <= r)
    {
        int mit = (l+r)>>1;
        if (sepuede(mit))
        {
            resp = mit;
            l = mit+1;
            continue;
        }
        r = mit-1;
    }
    cout << resp;
    return 0;
}

Compilation message

mecho.cpp: In function 'bool sepuede(int)':
mecho.cpp:72:10: warning: unused variable 'llego' [-Wunused-variable]
   72 |     bool llego = 0;
      |          ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Correct 0 ms 600 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 108 ms 22320 KB Output is correct
7 Runtime error 176 ms 65536 KB Execution killed with signal 9
8 Incorrect 2 ms 344 KB Output isn't correct
9 Incorrect 13 ms 7408 KB Output isn't correct
10 Incorrect 64 ms 28668 KB Output isn't correct
11 Incorrect 4 ms 1116 KB Output isn't correct
12 Runtime error 147 ms 65536 KB Execution killed with signal 9
13 Runtime error 262 ms 65536 KB Execution killed with signal 9
14 Execution timed out 1039 ms 46828 KB Time limit exceeded
15 Runtime error 157 ms 65536 KB Execution killed with signal 9
16 Runtime error 225 ms 65536 KB Execution killed with signal 9
17 Runtime error 146 ms 65536 KB Execution killed with signal 9
18 Runtime error 164 ms 65536 KB Execution killed with signal 9
19 Runtime error 138 ms 65536 KB Execution killed with signal 9
20 Runtime error 149 ms 65536 KB Execution killed with signal 9
21 Runtime error 142 ms 65536 KB Execution killed with signal 9
22 Runtime error 143 ms 65536 KB Execution killed with signal 9
23 Runtime error 140 ms 65536 KB Execution killed with signal 9
24 Runtime error 145 ms 65536 KB Execution killed with signal 9
25 Runtime error 138 ms 65536 KB Execution killed with signal 9
26 Runtime error 142 ms 65536 KB Execution killed with signal 9
27 Runtime error 139 ms 65536 KB Execution killed with signal 9
28 Runtime error 141 ms 65536 KB Execution killed with signal 9
29 Runtime error 139 ms 65536 KB Execution killed with signal 9
30 Runtime error 144 ms 65536 KB Execution killed with signal 9
31 Runtime error 139 ms 65536 KB Execution killed with signal 9
32 Runtime error 143 ms 65536 KB Execution killed with signal 9
33 Runtime error 147 ms 65536 KB Execution killed with signal 9
34 Runtime error 146 ms 65536 KB Execution killed with signal 9
35 Runtime error 149 ms 65536 KB Execution killed with signal 9
36 Runtime error 148 ms 65536 KB Execution killed with signal 9
37 Runtime error 144 ms 65536 KB Execution killed with signal 9
38 Runtime error 147 ms 65536 KB Execution killed with signal 9
39 Runtime error 148 ms 65536 KB Execution killed with signal 9
40 Runtime error 148 ms 65536 KB Execution killed with signal 9
41 Runtime error 150 ms 65536 KB Execution killed with signal 9
42 Runtime error 142 ms 65536 KB Execution killed with signal 9
43 Runtime error 149 ms 65536 KB Execution killed with signal 9
44 Runtime error 152 ms 65536 KB Execution killed with signal 9
45 Runtime error 177 ms 65536 KB Execution killed with signal 9
46 Runtime error 150 ms 65536 KB Execution killed with signal 9
47 Runtime error 153 ms 65536 KB Execution killed with signal 9
48 Runtime error 145 ms 65536 KB Execution killed with signal 9
49 Runtime error 155 ms 65536 KB Execution killed with signal 9
50 Runtime error 168 ms 65536 KB Execution killed with signal 9
51 Runtime error 149 ms 65536 KB Execution killed with signal 9
52 Runtime error 159 ms 65536 KB Execution killed with signal 9
53 Runtime error 155 ms 65536 KB Execution killed with signal 9
54 Runtime error 156 ms 65536 KB Execution killed with signal 9
55 Runtime error 178 ms 65536 KB Execution killed with signal 9
56 Runtime error 157 ms 65536 KB Execution killed with signal 9
57 Runtime error 163 ms 65536 KB Execution killed with signal 9
58 Runtime error 158 ms 65536 KB Execution killed with signal 9
59 Runtime error 161 ms 65536 KB Execution killed with signal 9
60 Runtime error 169 ms 65536 KB Execution killed with signal 9
61 Runtime error 170 ms 65536 KB Execution killed with signal 9
62 Runtime error 164 ms 65536 KB Execution killed with signal 9
63 Runtime error 164 ms 65536 KB Execution killed with signal 9
64 Runtime error 170 ms 65536 KB Execution killed with signal 9
65 Runtime error 185 ms 65536 KB Execution killed with signal 9
66 Runtime error 164 ms 65536 KB Execution killed with signal 9
67 Runtime error 166 ms 65536 KB Execution killed with signal 9
68 Runtime error 169 ms 65536 KB Execution killed with signal 9
69 Runtime error 180 ms 65536 KB Execution killed with signal 9
70 Runtime error 171 ms 65536 KB Execution killed with signal 9
71 Runtime error 165 ms 65536 KB Execution killed with signal 9
72 Runtime error 166 ms 65536 KB Execution killed with signal 9
73 Runtime error 253 ms 65536 KB Execution killed with signal 9
74 Runtime error 251 ms 65536 KB Execution killed with signal 9
75 Runtime error 250 ms 65536 KB Execution killed with signal 9
76 Runtime error 248 ms 65536 KB Execution killed with signal 9
77 Runtime error 251 ms 65536 KB Execution killed with signal 9
78 Runtime error 232 ms 65536 KB Execution killed with signal 9
79 Runtime error 233 ms 65536 KB Execution killed with signal 9
80 Runtime error 246 ms 65536 KB Execution killed with signal 9
81 Runtime error 217 ms 65536 KB Execution killed with signal 9
82 Runtime error 219 ms 65536 KB Execution killed with signal 9
83 Runtime error 195 ms 65536 KB Execution killed with signal 9
84 Runtime error 197 ms 65536 KB Execution killed with signal 9
85 Runtime error 208 ms 65536 KB Execution killed with signal 9
86 Runtime error 193 ms 65536 KB Execution killed with signal 9
87 Runtime error 195 ms 65536 KB Execution killed with signal 9
88 Runtime error 187 ms 65536 KB Execution killed with signal 9
89 Runtime error 182 ms 65536 KB Execution killed with signal 9
90 Runtime error 181 ms 65536 KB Execution killed with signal 9
91 Runtime error 197 ms 65536 KB Execution killed with signal 9
92 Runtime error 179 ms 65536 KB Execution killed with signal 9