Submission #798953

# Submission time Handle Problem Language Result Execution time Memory
798953 2023-07-31T07:58:44 Z yandabao Mecho (IOI09_mecho) C++17
29 / 100
229 ms 10628 KB
#include <iostream>
#include <vector>
#include <limits>
#include <map>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
#include <climits>
#include <string.h>
#include <fstream>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvi= vector<vector<int> >;
using vll = vector<long long>;
using vpi = vector<pair<int, int> >;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int, int>;
#define f first
#define s second
#define mp make_pair
//cin.tie(0)->sync_with_stdio(0);

int N, S;
vi dx, dy;
pi end;
vector<vector<char> > field;
vvi fromHive;


void BFS(int a, int b, vvi& fromMecho, int ad){
    queue<pair<pair<int, int>, int> > q;
    q.push(mp(mp(a, b), 0));

    while(!q.empty()){
        pair<pi, int> curr = q.front(); q.pop();
        if(field[curr.f.f][curr.f.s] == 'T'){
            continue;
        }
        if(fromHive[curr.f.f][curr.f.s] < curr.s/S + ad + (curr.s%S == 0 ? 0 : 1)){
            continue;
        }
        if(fromMecho[curr.f.f][curr.f.s] > curr.s/S + ad + (curr.s%S == 0 ? 0 : 1)){
            fromMecho[curr.f.f][curr.f.s] = curr.s/S + ad + (curr.s%S == 0 ? 0 : 1);
            for (int i = 0; i < 4; i++)
            {
                if(curr.f.f + dx[i] < 0 || curr.f.f + dx[i] >= N || curr.f.s + dy[i] < 0 || curr.f.s >= N){
                    continue;
                }
                q.push(mp(mp(curr.f.f + dx[i], curr.f.s + dy[i]), curr.s + 1));
            }
        }
    }
}

int main(){
    cin >> N >> S;
    dx = {-1, 1, 0, 0};
    dy = {0, 0, -1, 1};
    vi row(N, INT_MAX);
    fromHive.rsz(N);
    field.rsz(N);
    for (int i = 0; i < N; i++)
    {
        fromHive[i] = row;
        field[i].rsz(N);
    }

    pi start, end;
    vpi hive;

    for (int i = 0; i < N; i++)
    {
        string str; cin >> str;
        for (int j = 0; j < N; j++)
        {
            field[i][j] = str[j];
            if(str[j] == 'M'){
                start = mp(i, j);
            }
            if(str[j] == 'D'){
                end = mp(i, j);
            }
            if(str[j] == 'H'){
                hive.pb(mp(i, j));
            }
        }
    }

    queue<pair<pair<int, int>, int> > q;
    for (int i = 0; i < sz(hive); i++)
    {
        q.push(mp(hive[i], 0));
    }

    while(!q.empty()){
        pair<pi, int> curr = q.front(); q.pop();
        if(field[curr.f.f][curr.f.s] != 'G' && field[curr.f.f][curr.f.s] != 'H'){
            continue;
        }
        if(fromHive[curr.f.f][curr.f.s] > curr.s){
            fromHive[curr.f.f][curr.f.s] = curr.s;
            for (int i = 0; i < 4; i++)
            {
                if(curr.f.f + dx[i] < 0 || curr.f.f + dx[i] >= N || curr.f.s + dy[i] < 0 || curr.f.s + dy[i] >= N){
                    continue;
                }
                q.push(mp(mp(curr.f.f + dx[i], curr.f.s + dy[i]), curr.s + 1));
            }
        }
    }

    int lo = 0, hi = INT_MAX/2;
    while(lo < hi){
        int mid = (lo + hi + 1)/2;
        vi row(N, INT_MAX);
        vvi fromMecho(N);
        for (int i = 0; i < N; i++)
        {
            fromMecho[i] = row;
        }
        BFS(start.f, start.s, fromMecho, mid);
        // for (int i = 0; i < sz(fromMecho); i++)
        // {
        //     for (int j = 0; j < N; j++)
        //     {
        //         cout << fromMecho[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        if(fromMecho[end.f][end.s] == INT_MAX){
            hi = mid - 1;
        } else {
            lo = mid;
        }
    }
    cout << lo; 

    // for (int i = 0; i < N; i++)
    // {
    //     for (int j = 0; j < N; j++)
    //     {
    //         cout << fromHive[i][j] << " ";
    //     }
    //     cout << endl;
    // }


}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Runtime error 1 ms 340 KB Execution killed with signal 6
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 149 ms 6144 KB Output is correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Runtime error 1 ms 468 KB Execution killed with signal 6
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Correct 1 ms 212 KB Output is correct
17 Incorrect 0 ms 212 KB Output isn't correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 0 ms 212 KB Output isn't correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Correct 1 ms 212 KB Output is correct
23 Incorrect 1 ms 212 KB Output isn't correct
24 Correct 1 ms 212 KB Output is correct
25 Incorrect 1 ms 212 KB Output isn't correct
26 Correct 1 ms 212 KB Output is correct
27 Incorrect 1 ms 340 KB Output isn't correct
28 Correct 1 ms 340 KB Output is correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Correct 1 ms 340 KB Output is correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Correct 1 ms 340 KB Output is correct
33 Incorrect 7 ms 1364 KB Output isn't correct
34 Correct 8 ms 1364 KB Output is correct
35 Runtime error 10 ms 2668 KB Execution killed with signal 6
36 Incorrect 8 ms 1756 KB Output isn't correct
37 Correct 8 ms 1748 KB Output is correct
38 Correct 46 ms 1816 KB Output is correct
39 Incorrect 10 ms 2004 KB Output isn't correct
40 Correct 10 ms 2136 KB Output is correct
41 Runtime error 21 ms 4120 KB Execution killed with signal 6
42 Incorrect 13 ms 2516 KB Output isn't correct
43 Correct 15 ms 2560 KB Output is correct
44 Correct 76 ms 2568 KB Output is correct
45 Incorrect 14 ms 2972 KB Output isn't correct
46 Correct 14 ms 2900 KB Output is correct
47 Runtime error 23 ms 5984 KB Execution killed with signal 6
48 Incorrect 17 ms 3412 KB Output isn't correct
49 Correct 18 ms 3512 KB Output is correct
50 Correct 116 ms 3628 KB Output is correct
51 Incorrect 21 ms 4080 KB Output isn't correct
52 Correct 30 ms 4076 KB Output is correct
53 Runtime error 33 ms 8224 KB Execution killed with signal 6
54 Incorrect 25 ms 4672 KB Output isn't correct
55 Correct 28 ms 4708 KB Output is correct
56 Correct 155 ms 4740 KB Output is correct
57 Incorrect 30 ms 5196 KB Output isn't correct
58 Correct 25 ms 5284 KB Output is correct
59 Runtime error 54 ms 10628 KB Execution killed with signal 6
60 Incorrect 29 ms 5920 KB Output isn't correct
61 Correct 30 ms 5920 KB Output is correct
62 Correct 204 ms 6124 KB Output is correct
63 Correct 140 ms 6108 KB Output is correct
64 Correct 229 ms 6092 KB Output is correct
65 Correct 228 ms 6088 KB Output is correct
66 Incorrect 187 ms 6168 KB Output isn't correct
67 Incorrect 164 ms 6108 KB Output isn't correct
68 Correct 80 ms 6128 KB Output is correct
69 Correct 69 ms 6268 KB Output is correct
70 Correct 64 ms 6120 KB Output is correct
71 Correct 64 ms 6152 KB Output is correct
72 Incorrect 62 ms 6144 KB Output isn't correct
73 Incorrect 127 ms 6176 KB Output isn't correct
74 Correct 104 ms 6192 KB Output is correct
75 Correct 112 ms 6112 KB Output is correct
76 Correct 103 ms 6116 KB Output is correct
77 Correct 105 ms 6116 KB Output is correct
78 Incorrect 126 ms 6112 KB Output isn't correct
79 Correct 89 ms 6196 KB Output is correct
80 Correct 103 ms 6192 KB Output is correct
81 Correct 119 ms 6188 KB Output is correct
82 Correct 108 ms 6104 KB Output is correct
83 Correct 138 ms 6168 KB Output is correct
84 Correct 122 ms 6140 KB Output is correct
85 Correct 126 ms 6172 KB Output is correct
86 Correct 131 ms 6164 KB Output is correct
87 Correct 122 ms 6168 KB Output is correct
88 Correct 150 ms 6136 KB Output is correct
89 Correct 135 ms 6084 KB Output is correct
90 Correct 149 ms 6160 KB Output is correct
91 Correct 140 ms 6144 KB Output is correct
92 Correct 137 ms 6132 KB Output is correct