Submission #553237

# Submission time Handle Problem Language Result Execution time Memory
553237 2022-04-25T07:06:54 Z amirallisson Mecho (IOI09_mecho) C++14
22 / 100
123 ms 7636 KB
#include <bits/stdc++.h>
/*--------------------------------------------------------------------*/
#define INF 3*100*1000 + 5
#define MAX 1000000
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define intt int64_t
#define piic pair<int64_t, int64_t>
typedef long long ll;
using namespace std;

/*--------------------------------------------------------------------*/

int n, s;
pii b, home;
queue<pii> hives;
vector<string> grid;
int filltime[900][900]{INT_MAX}, beetime[900][900], visited[900][900];
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
int inside(int x, int y){
    return (x> -1 && x < n && y > -1 && y < n && grid[x][y] != 'T');
}



int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(0); cin.tie(0);
    fill(filltime[0], filltime[0] + 900*900, INT_MAX);

    if(2 >= INT_MAX) cout << "Error\n";

    cin >> n >> s;
    for(int i = 0; i < n; ++i){
        string str;
        cin >> str;
        grid.pb(str);
        for(int j = 0; j < (int)str.length(); ++j){
            if (str[j] == 'M') b = make_pair(i, j);
            if (str[j] == 'D') home = make_pair(i, j);
            if(str[j] == 'H'){
                    hives.push(make_pair(i, j));
                    filltime[i][j] = 0;
            }
        }
    }
    while(!hives.empty()){
        pii bee = hives.front();
        hives.pop();
        int x,y;
        x = bee.fi; y = bee.se;

        for(int i = 0; i < 4; ++i){
            if(!inside(x + dx[i], y + dy[i]) || grid[x+dx[i]][y+dy[i]] == 'D') continue;
            if(filltime[x+dx[i]][y+dy[i]] != INT_MAX)
                filltime[x+dx[i]][y+dy[i]] = min(filltime[x+dx[i]][y+dy[i]], filltime[x][y] + 1);
            else {
                filltime[x+dx[i]][y+dy[i]] = filltime[x][y] + 1;
                hives.push(make_pair(x + dx[i], y + dy[i]));
            }
        }
    }

    int lo = 0, hi = filltime[b.fi][b.se];
    int ans = 0;
    bool realpos = false;
   while(lo < hi){
        queue<tuple<int, int, int, int>> q;
        int tempans = lo + (hi-lo)/2;
        bool pos = false;
        fill(visited[0], visited[0] + 900*900, 0);
        visited[b.fi][b.se] = 1;
        q.push(make_tuple(b.fi, b.se, tempans, 0));
       // cout << "New Round "  << tempans << '\n';
        while(!q.empty()){
            tuple<int, int, int, int> cur = q.front();
            q.pop();
            int x = get<0>(cur);
            int y = get<1> (cur);
            int a = get<2> (cur);
            int res = get<3> (cur);

            //cout << x << ' ' << y << ' ' << a << ' ' << res << ' ' << q.size() << ' ' << filltime[x][y] << '\n';

            if(a + (double)res/s >= filltime[x][y]) continue;
            if(x == home.fi && y == home.se) {
                pos = true;
                realpos = true;
              //  cout << "Success!\n";
                break;
            }
            int x1, y1;
            if(res == s-1) {
                y1 = 0;
                x1 = a + 1;
            } else {
                x1 = a;
                y1 = res + 1;
            }
            for(int i = 0; i < 4; ++i) {
                if(!inside(x+dx[i],y+dy[i])) continue;
                if(visited[x+dx[i]][y+dy[i]]) continue;
                visited[x+dx[i]][y+dy[i]] = 1;
                q.push(make_tuple(x+dx[i], y+dy[i], x1, y1));
            }
        }
       // cout << pos << '\n';
        if(realpos) {
            ans = max(ans, tempans);
            lo = tempans + 1;
        } else {
            hi = tempans;
        }
    }

    if(realpos) cout << ans << '\n';
    else cout << -1 << '\n';
    return 0;

}

Compilation message

mecho.cpp: In function 'int main(int, const char**)':
mecho.cpp:73:14: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
   73 |         bool pos = false;
      |              ^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6612 KB Output is correct
2 Correct 4 ms 6612 KB Output is correct
3 Incorrect 3 ms 6612 KB Output isn't correct
4 Correct 3 ms 6612 KB Output is correct
5 Correct 3 ms 6612 KB Output is correct
6 Correct 3 ms 6612 KB Output is correct
7 Incorrect 69 ms 7372 KB Output isn't correct
8 Correct 4 ms 6584 KB Output is correct
9 Correct 3 ms 6612 KB Output is correct
10 Incorrect 4 ms 6612 KB Output isn't correct
11 Incorrect 3 ms 6612 KB Output isn't correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 3 ms 6612 KB Output is correct
14 Correct 4 ms 6612 KB Output is correct
15 Incorrect 4 ms 6612 KB Output isn't correct
16 Incorrect 4 ms 6612 KB Output isn't correct
17 Incorrect 4 ms 6612 KB Output isn't correct
18 Incorrect 4 ms 6612 KB Output isn't correct
19 Incorrect 4 ms 6612 KB Output isn't correct
20 Incorrect 4 ms 6624 KB Output isn't correct
21 Incorrect 4 ms 6596 KB Output isn't correct
22 Incorrect 4 ms 6612 KB Output isn't correct
23 Incorrect 4 ms 6612 KB Output isn't correct
24 Incorrect 4 ms 6612 KB Output isn't correct
25 Incorrect 5 ms 6612 KB Output isn't correct
26 Incorrect 4 ms 6612 KB Output isn't correct
27 Incorrect 5 ms 6596 KB Output isn't correct
28 Incorrect 4 ms 6612 KB Output isn't correct
29 Incorrect 4 ms 6684 KB Output isn't correct
30 Incorrect 4 ms 6612 KB Output isn't correct
31 Incorrect 4 ms 6612 KB Output isn't correct
32 Incorrect 5 ms 6612 KB Output isn't correct
33 Incorrect 6 ms 6740 KB Output isn't correct
34 Incorrect 7 ms 6740 KB Output isn't correct
35 Correct 18 ms 6740 KB Output is correct
36 Incorrect 7 ms 6740 KB Output isn't correct
37 Incorrect 6 ms 6740 KB Output isn't correct
38 Incorrect 21 ms 6868 KB Output isn't correct
39 Incorrect 8 ms 6812 KB Output isn't correct
40 Incorrect 8 ms 6868 KB Output isn't correct
41 Incorrect 32 ms 6812 KB Output isn't correct
42 Incorrect 9 ms 6868 KB Output isn't correct
43 Incorrect 8 ms 6852 KB Output isn't correct
44 Incorrect 43 ms 6868 KB Output isn't correct
45 Incorrect 10 ms 6996 KB Output isn't correct
46 Incorrect 9 ms 7012 KB Output isn't correct
47 Incorrect 49 ms 7012 KB Output isn't correct
48 Incorrect 11 ms 7080 KB Output isn't correct
49 Incorrect 12 ms 7028 KB Output isn't correct
50 Incorrect 52 ms 6988 KB Output isn't correct
51 Incorrect 12 ms 7052 KB Output isn't correct
52 Incorrect 13 ms 7124 KB Output isn't correct
53 Correct 55 ms 7052 KB Output is correct
54 Incorrect 13 ms 7124 KB Output isn't correct
55 Incorrect 11 ms 7124 KB Output isn't correct
56 Correct 67 ms 7208 KB Output is correct
57 Incorrect 13 ms 7252 KB Output isn't correct
58 Incorrect 13 ms 7252 KB Output isn't correct
59 Correct 81 ms 7284 KB Output is correct
60 Incorrect 18 ms 7264 KB Output isn't correct
61 Incorrect 14 ms 7252 KB Output isn't correct
62 Incorrect 98 ms 7292 KB Output isn't correct
63 Correct 98 ms 7356 KB Output is correct
64 Incorrect 93 ms 7352 KB Output isn't correct
65 Incorrect 123 ms 7348 KB Output isn't correct
66 Incorrect 108 ms 7352 KB Output isn't correct
67 Correct 119 ms 7348 KB Output is correct
68 Correct 47 ms 7380 KB Output is correct
69 Incorrect 34 ms 7372 KB Output isn't correct
70 Incorrect 33 ms 7380 KB Output isn't correct
71 Correct 34 ms 7300 KB Output is correct
72 Correct 29 ms 7288 KB Output is correct
73 Correct 29 ms 7636 KB Output is correct
74 Incorrect 50 ms 7548 KB Output isn't correct
75 Incorrect 48 ms 7636 KB Output isn't correct
76 Incorrect 50 ms 7556 KB Output isn't correct
77 Incorrect 58 ms 7544 KB Output isn't correct
78 Correct 63 ms 7600 KB Output is correct
79 Incorrect 38 ms 7504 KB Output isn't correct
80 Incorrect 50 ms 7508 KB Output isn't correct
81 Incorrect 60 ms 7592 KB Output isn't correct
82 Incorrect 52 ms 7508 KB Output isn't correct
83 Correct 68 ms 7508 KB Output is correct
84 Incorrect 58 ms 7476 KB Output isn't correct
85 Incorrect 55 ms 7564 KB Output isn't correct
86 Incorrect 64 ms 7500 KB Output isn't correct
87 Incorrect 59 ms 7472 KB Output isn't correct
88 Correct 79 ms 7532 KB Output is correct
89 Incorrect 75 ms 7516 KB Output isn't correct
90 Incorrect 67 ms 7484 KB Output isn't correct
91 Incorrect 64 ms 7512 KB Output isn't correct
92 Incorrect 67 ms 7408 KB Output isn't correct