Submission #1074366

# Submission time Handle Problem Language Result Execution time Memory
1074366 2024-08-25T10:06:08 Z TheEpicCowOfLife Mecho (IOI09_mecho) C++14
0 / 100
2 ms 1660 KB
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
 
using namespace std;
 
typedef pair<int,int> pii;
 
bool is_g[805][805];
bool pushed[805][805];
 
bool bocc[805][805];
 
int sx, sy;
int fx, fy;
 
int n,s;
 
vector<pii> hv;
 
queue<pii> mq;
queue<pii> bq;
 
int ax[4] = {0,1,0,-1};
int ay[4] = {1,0,-1,0};
// can mecho make it back to the hive waiting k minutes?
bool decision(int k){
    queue<pii> mq;
    queue<pii> bq;
    memset(pushed, 0, sizeof(pushed));
    memset(bocc, 0, sizeof(bocc));
    mq.push({sx,sy});
    pushed[sx][sy] = true;
    for (pii cur : hv){
        bq.push(cur);
        bocc[cur.first][cur.second] = true;
    }
 
    for (int vi = 0; vi < k; vi++){
        int sz = bq.size();
        for (int i = 0 ; i < sz; i++){
            pii cur = bq.front();
            bq.pop();
            for (int j = 0; j < 4; j++){
                int cx = cur.first + ax[j];
                int cy = cur.second + ay[j];
                if (!bocc[cx][cy] && is_g[cx][cy]){
                    bocc[cx][cy] = true;
                    bq.push({cx,cy});
                }
            }
        }
    }
 
    while(true){
        int sz;
        for (int vi = 0; vi < s; vi++){
            sz = mq.size();
            for (int i = 0 ; i < sz; i++){
                pii cur = mq.front();
                mq.pop();
                if (bocc[cur.first][cur.second]) continue;
                for (int j = 0; j < 4; j++){
                    int cx = cur.first + ax[j];
                    int cy = cur.second + ay[j];
                    if (cx == fx && cy == fy) return true;
                    if (!bocc[cx][cy] && is_g[cx][cy] && !pushed[cx][cy]){
                        pushed[cx][cy] = true;
                        mq.push({cx,cy});
                    }
                }
            }
        }
        if (sz == 0) return false;
        sz = bq.size();
        for (int i = 0 ; i < sz; i++){
            pii cur = bq.front();
            bq.pop();
            for (int j = 0; j < 4; j++){
                int cx = cur.first + ax[j];
                int cy = cur.second + ay[j];
                if (!bocc[cx][cy] && is_g[cx][cy]){
                    bocc[cx][cy] = true;
                    bq.push({cx,cy});
                }
            }
        }
    }
 
}
 
int main(){
    freopen("mecho.in", "r", stdin);
    freopen("mecho.out", "w", stdout);
    scanf("%d %d", &n, &s);
    for (int y = 1; y <= n; y++){
        for (int x = 1; x <= n; x++){
            char inst;
            scanf(" %c", &inst);
            if (inst == 'G'){
                is_g[x][y] = true;
            }
            else if (inst == 'H'){
                hv.push_back({x,y});
            }
            else if (inst == 'M'){
                sx = x;
                sy = y;
                is_g[x][y] = true;
            }
            else if (inst == 'D'){
                fx = x;
                fy = y;
            }
        }
    }
 
    int best = -1;
    int lo = 0;
    int hi = n * n/2 + 1;
    while (lo <= hi){
        int mid = (lo + hi)/2;
        if (decision(mid)){
            lo = mid + 1;
            best = mid;
        }
        else{
            hi = mid - 1;
        }
    }
 
    printf("%d\n", best);
 
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:96:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     freopen("mecho.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:97:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |     freopen("mecho.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |     scanf("%d %d", &n, &s);
      |     ~~~~~^~~~~~~~~~~~~~~~~
mecho.cpp:102:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |             scanf(" %c", &inst);
      |             ~~~~~^~~~~~~~~~~~~~
mecho.cpp: In function 'bool decision(int)':
mecho.cpp:77:9: warning: 'sz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |         if (sz == 0) return false;
      |         ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1624 KB Output isn't correct
2 Incorrect 1 ms 1628 KB Output isn't correct
3 Incorrect 1 ms 1628 KB Output isn't correct
4 Incorrect 1 ms 1628 KB Output isn't correct
5 Incorrect 1 ms 1628 KB Output isn't correct
6 Incorrect 1 ms 1624 KB Output isn't correct
7 Incorrect 1 ms 1628 KB Output isn't correct
8 Incorrect 1 ms 1628 KB Output isn't correct
9 Incorrect 1 ms 1628 KB Output isn't correct
10 Incorrect 1 ms 1628 KB Output isn't correct
11 Incorrect 1 ms 1628 KB Output isn't correct
12 Incorrect 1 ms 1628 KB Output isn't correct
13 Incorrect 1 ms 1628 KB Output isn't correct
14 Incorrect 1 ms 1628 KB Output isn't correct
15 Incorrect 1 ms 1628 KB Output isn't correct
16 Incorrect 1 ms 1628 KB Output isn't correct
17 Incorrect 1 ms 1628 KB Output isn't correct
18 Incorrect 2 ms 1628 KB Output isn't correct
19 Incorrect 2 ms 1628 KB Output isn't correct
20 Incorrect 1 ms 1560 KB Output isn't correct
21 Incorrect 1 ms 1628 KB Output isn't correct
22 Incorrect 1 ms 1628 KB Output isn't correct
23 Incorrect 1 ms 1628 KB Output isn't correct
24 Incorrect 1 ms 1628 KB Output isn't correct
25 Incorrect 1 ms 1628 KB Output isn't correct
26 Incorrect 1 ms 1628 KB Output isn't correct
27 Incorrect 1 ms 1628 KB Output isn't correct
28 Incorrect 1 ms 1628 KB Output isn't correct
29 Incorrect 1 ms 1628 KB Output isn't correct
30 Incorrect 1 ms 1628 KB Output isn't correct
31 Incorrect 1 ms 1628 KB Output isn't correct
32 Incorrect 1 ms 1628 KB Output isn't correct
33 Incorrect 1 ms 1492 KB Output isn't correct
34 Incorrect 1 ms 1628 KB Output isn't correct
35 Incorrect 1 ms 1628 KB Output isn't correct
36 Incorrect 1 ms 1628 KB Output isn't correct
37 Incorrect 2 ms 1628 KB Output isn't correct
38 Incorrect 1 ms 1628 KB Output isn't correct
39 Incorrect 1 ms 1660 KB Output isn't correct
40 Incorrect 1 ms 1628 KB Output isn't correct
41 Incorrect 1 ms 1628 KB Output isn't correct
42 Incorrect 1 ms 1628 KB Output isn't correct
43 Incorrect 1 ms 1628 KB Output isn't correct
44 Incorrect 1 ms 1628 KB Output isn't correct
45 Incorrect 1 ms 1632 KB Output isn't correct
46 Incorrect 1 ms 1628 KB Output isn't correct
47 Incorrect 1 ms 1628 KB Output isn't correct
48 Incorrect 1 ms 1628 KB Output isn't correct
49 Incorrect 2 ms 1632 KB Output isn't correct
50 Incorrect 1 ms 1624 KB Output isn't correct
51 Incorrect 1 ms 1624 KB Output isn't correct
52 Incorrect 1 ms 1632 KB Output isn't correct
53 Incorrect 1 ms 1632 KB Output isn't correct
54 Incorrect 2 ms 1636 KB Output isn't correct
55 Incorrect 1 ms 1628 KB Output isn't correct
56 Incorrect 1 ms 1636 KB Output isn't correct
57 Incorrect 1 ms 1640 KB Output isn't correct
58 Incorrect 1 ms 1640 KB Output isn't correct
59 Incorrect 1 ms 1640 KB Output isn't correct
60 Incorrect 1 ms 1640 KB Output isn't correct
61 Incorrect 1 ms 1628 KB Output isn't correct
62 Incorrect 1 ms 1628 KB Output isn't correct
63 Incorrect 1 ms 1640 KB Output isn't correct
64 Incorrect 1 ms 1640 KB Output isn't correct
65 Incorrect 1 ms 1640 KB Output isn't correct
66 Incorrect 1 ms 1632 KB Output isn't correct
67 Incorrect 1 ms 1624 KB Output isn't correct
68 Incorrect 1 ms 1628 KB Output isn't correct
69 Incorrect 1 ms 1632 KB Output isn't correct
70 Incorrect 1 ms 1632 KB Output isn't correct
71 Incorrect 1 ms 1640 KB Output isn't correct
72 Incorrect 1 ms 1636 KB Output isn't correct
73 Incorrect 1 ms 1628 KB Output isn't correct
74 Incorrect 1 ms 1632 KB Output isn't correct
75 Incorrect 1 ms 1636 KB Output isn't correct
76 Incorrect 1 ms 1632 KB Output isn't correct
77 Incorrect 1 ms 1632 KB Output isn't correct
78 Incorrect 1 ms 1636 KB Output isn't correct
79 Incorrect 1 ms 1628 KB Output isn't correct
80 Incorrect 1 ms 1632 KB Output isn't correct
81 Incorrect 1 ms 1636 KB Output isn't correct
82 Incorrect 1 ms 1628 KB Output isn't correct
83 Incorrect 1 ms 1628 KB Output isn't correct
84 Incorrect 1 ms 1636 KB Output isn't correct
85 Incorrect 1 ms 1628 KB Output isn't correct
86 Incorrect 1 ms 1588 KB Output isn't correct
87 Incorrect 1 ms 1628 KB Output isn't correct
88 Incorrect 1 ms 1628 KB Output isn't correct
89 Incorrect 2 ms 1644 KB Output isn't correct
90 Incorrect 1 ms 1624 KB Output isn't correct
91 Incorrect 1 ms 1628 KB Output isn't correct
92 Incorrect 1 ms 1628 KB Output isn't correct