Submission #892653

# Submission time Handle Problem Language Result Execution time Memory
892653 2023-12-25T16:14:25 Z seriouslyFlawed Mecho (IOI09_mecho) C++17
44 / 100
1000 ms 7764 KB
#pragma GCC optimize("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>

using namespace std;

// Shortcuts for common operations
#define pb push_back
#define ppb pop_back
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define endl "\n"

// Type definitions for convenience
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef unordered_set<int> usi;
typedef unordered_map<int, int> umii;

// Debugging macros
#define debug(x) cerr << #x << " = " << (x) << '\n'
#define debug_vector(v) _debug_vector(#v, v)
template<typename T>
void _debug_vector(const string& name, const vector<T>& a) {
    cerr << name << " = [ ";
    for(const auto &x : a) cerr << x << ' ';
    cerr << "]\n";
}

// I/O redirection for local testing
#define iofile(io) \
        freopen((io + ".in").c_str(), "r", stdin); \
        freopen((io + ".out").c_str(), "w", stdout);

// delta for floodfill
vi dx = {0, 1, 0, -1};
vi dy = {1, 0, -1, 0};

// extended deltas for floodfill
vi edx = {0, 1, 0, -1, 1, 1, -1, -1};
vi edy = {1, 0, -1, 0, 1, -1, 1, -1};

// Common outputs
void yes() { cout << "YES" << '\n'; }
void no() { cout << "NO" << '\n'; }

// cin.tie(0)->sync_with_stdio(0);
#define INT_MIN -1000000000
#define INT_MAX 1000000000

void fx() {
    // Functionality for fx
    int n, k;
    cin >> n >> k;

    vector<string>tab(n);
    vvi bee(n, vi(n, INT_MAX));
    vii hives;
    pii start;

    for(int i = 0; i < n; i++){
        cin >> tab[i];
        for(int j = 0; j < n; j++){
            if(tab[i][j] == 'M') start = {i, j};
            else if(tab[i][j] == 'H') hives.pb({i, j});
        }
    }

    queue<pair<int, pii>>q;
    for(auto &hive: hives){
        q.push({0, hive});
        bee[hive.f][hive.s] = 0;
    }

    while(!q.empty()){
        auto &[t, hive] = q.front();
        q.pop();
        auto &[x, y] = hive;
        
        for(int i = 0; i < 4; i++){
            auto [X, Y] = make_pair(x+dx[i], y+dy[i]);
            if(X >= 0 and X < n and Y >= 0 and Y < n and (tab[X][Y] == 'G' or tab[X][Y] == 'M') and bee[X][Y] > t + 1){
                q.push({t+1, {X, Y}});
                bee[X][Y] = t+1;
            }
        }
    }

    queue<pair<array<int, 3>, pii>>que;
    vector<vi>best(n, vi(n, INT_MIN)); // <- see init.
    que.push({{0, bee[start.f][start.s], k}, {start.f, start.s}}); //<- sure about init?
    best[start.f][start.s] = bee[start.f][start.s];
    int res = INT_MIN;

    while(!que.empty()){
        auto [T, C] = que.front();
        que.pop();
        auto [t, s, steps] = T;
        auto [x, y] = C;

        if(tab[x][y] == 'D') res = max(res, best[x][y]);
        
        for(int i = 0; i < 4; i++){
            auto [X, Y] = make_pair(x + dx[i], y + dy[i]);

            if(X >= 0 and X < n and Y >= 0 and Y < n and tab[X][Y] != 'T' and (bee[X][Y] > (steps?t:t+1)) and best[X][Y] < min(s, bee[X][Y] - (steps?t:t+1))){
                que.push({{(steps?t:t+1), min(s, bee[X][Y] - (steps?t:t+1)), (steps?steps-1:k-1)}, {X, Y}});
                best[X][Y] = max(best[X][Y], min(s, bee[X][Y] -(steps?t:t+1)));
            }
        }
    }

    cout << ((res <= 0)?-1:res-1) << endl;
}

int main() {
    // Uncomment the following lines for file I/O
    // iofile(string("hello"))
    cin.tie(0)->sync_with_stdio(0);

    
    // Uncomment the following lines for multiple test cases
    // int t; cin >> t;
    // while(t--) fx();
    
    // Single test case
    fx();
    
    return 0;
}

Compilation message

mecho.cpp:54: warning: "INT_MIN" redefined
   54 | #define INT_MIN -1000000000
      | 
In file included from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from mecho.cpp:4:
/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:118: note: this is the location of the previous definition
  118 | #define INT_MIN (-INT_MAX - 1)
      | 
mecho.cpp:55: warning: "INT_MAX" redefined
   55 | #define INT_MAX 1000000000
      | 
In file included from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from mecho.cpp:4:
/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:120: note: this is the location of the previous definition
  120 | #define INT_MAX __INT_MAX__
      |
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 158 ms 6312 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 0 ms 348 KB Output is correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 0 ms 348 KB Output isn't correct
24 Correct 0 ms 348 KB Output is correct
25 Incorrect 0 ms 348 KB Output isn't correct
26 Correct 1 ms 348 KB Output is correct
27 Incorrect 0 ms 348 KB Output isn't correct
28 Correct 0 ms 348 KB Output is correct
29 Incorrect 0 ms 348 KB Output isn't correct
30 Correct 0 ms 348 KB Output is correct
31 Incorrect 0 ms 348 KB Output isn't correct
32 Correct 0 ms 348 KB Output is correct
33 Incorrect 2 ms 1372 KB Output isn't correct
34 Correct 3 ms 1368 KB Output is correct
35 Correct 169 ms 1624 KB Output is correct
36 Incorrect 3 ms 1880 KB Output isn't correct
37 Correct 4 ms 1880 KB Output is correct
38 Correct 254 ms 2252 KB Output is correct
39 Incorrect 6 ms 2136 KB Output isn't correct
40 Correct 5 ms 2136 KB Output is correct
41 Correct 371 ms 2644 KB Output is correct
42 Incorrect 4 ms 2652 KB Output isn't correct
43 Correct 6 ms 2652 KB Output is correct
44 Correct 506 ms 3032 KB Output is correct
45 Incorrect 5 ms 3164 KB Output isn't correct
46 Correct 7 ms 3164 KB Output is correct
47 Correct 698 ms 3832 KB Output is correct
48 Incorrect 6 ms 3676 KB Output isn't correct
49 Correct 8 ms 3720 KB Output is correct
50 Correct 899 ms 4492 KB Output is correct
51 Incorrect 8 ms 4188 KB Output isn't correct
52 Correct 9 ms 4188 KB Output is correct
53 Execution timed out 1093 ms 5348 KB Time limit exceeded
54 Incorrect 9 ms 4696 KB Output isn't correct
55 Correct 11 ms 4700 KB Output is correct
56 Execution timed out 1083 ms 6224 KB Time limit exceeded
57 Incorrect 10 ms 5468 KB Output isn't correct
58 Correct 13 ms 5468 KB Output is correct
59 Execution timed out 1090 ms 6488 KB Time limit exceeded
60 Incorrect 13 ms 5976 KB Output isn't correct
61 Correct 17 ms 5980 KB Output is correct
62 Execution timed out 1065 ms 7764 KB Time limit exceeded
63 Incorrect 21 ms 6232 KB Output isn't correct
64 Incorrect 33 ms 5996 KB Output isn't correct
65 Incorrect 31 ms 5976 KB Output isn't correct
66 Incorrect 28 ms 5980 KB Output isn't correct
67 Correct 21 ms 5976 KB Output is correct
68 Correct 24 ms 6232 KB Output is correct
69 Correct 24 ms 6036 KB Output is correct
70 Correct 22 ms 6232 KB Output is correct
71 Correct 21 ms 6488 KB Output is correct
72 Correct 25 ms 6236 KB Output is correct
73 Correct 24 ms 6276 KB Output is correct
74 Incorrect 455 ms 6896 KB Output isn't correct
75 Correct 147 ms 6304 KB Output is correct
76 Correct 167 ms 6480 KB Output is correct
77 Correct 160 ms 6544 KB Output is correct
78 Correct 38 ms 6236 KB Output is correct
79 Incorrect 83 ms 6232 KB Output isn't correct
80 Incorrect 47 ms 6344 KB Output isn't correct
81 Correct 27 ms 6232 KB Output is correct
82 Incorrect 50 ms 6236 KB Output isn't correct
83 Correct 73 ms 6300 KB Output is correct
84 Correct 295 ms 6484 KB Output is correct
85 Correct 204 ms 6372 KB Output is correct
86 Correct 200 ms 6484 KB Output is correct
87 Correct 131 ms 6336 KB Output is correct
88 Correct 253 ms 6484 KB Output is correct
89 Correct 485 ms 6828 KB Output is correct
90 Correct 125 ms 6232 KB Output is correct
91 Correct 437 ms 7592 KB Output is correct
92 Correct 324 ms 6740 KB Output is correct