Submission #499688

# Submission time Handle Problem Language Result Execution time Memory
499688 2021-12-29T08:49:19 Z tphuc2908 Mecho (IOI09_mecho) C++14
38 / 100
270 ms 6336 KB
#include<bits/stdc++.h>

using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define repi(i,x,y) for(int i = x; i >= y; --i)
#define ci(x) int x; cin>> x
#define TC(t) ci(t); while(t--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define cii(x, y) ci(x); ci(y)
#define ciii(x, y, z) ci(x); ci(y); ci(z)
#define mp make_pair
//#define int long long
typedef long long ll;
typedef vector<int> vi;
const int N = 8e2 + 5;
const int mod = 1e9 + 7;
const int mod1 = 1e9 + 9;
const int pi = 31;
const int inf = 1e9 + 5;
const int block = 330;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

void readfile(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("text.inp", "r", stdin);
    #endif // ONLINE_JUDGE
//    freopen("gravity.in", "r", stdin);
//    freopen("gravity.out", "w", stdout);
}

int n, s;
char a[N][N];
pair<int,int> st, e;

void inp(){
    cin >> n >> s;
    rep(i,1,n)
        rep(j,1,n){
            cin >> a[i][j];
            if(a[i][j]=='M')
                st = mp(i, j);
            if(a[i][j]=='D')
                e = mp(i, j);
        }
}

int d[N][N], d1[N][N];

void bfs_multi_source(){
    queue<pair<int,int> > q;
    rep(i,1,n)
        rep(j,1,n){
            d1[i][j] = inf;
            if(a[i][j]=='H')
                q.push(mp(i ,j)), d1[i][j] = 0;
        }
    while(!q.empty()){
        pair<int,int> top = q.front();
        q.pop();
        rep(i,0,3){
            int x = top.fi + dx[i];
            int y = top.se + dy[i];
            if(1 <= x && x <= n && 1 <= y && y <= n && a[x][y]!='T' && d1[x][y] > d1[top.fi][top.se] + 1){
                d1[x][y] = d1[top.fi][top.se] + 1;
                q.push(mp(x,y));
            }
        }
    }
}

void bfs(int x, int y, int ti){
    rep(i,1,n)
        rep(j,1,n)
            d[i][j] = inf;
    queue<pair<int,int> > q;
    q.push(mp(x, y));
    d[x][y] = ti;
    while(!q.empty()){
        auto top = q.front();
        q.pop();
        rep(i,0,3){
            int x = top.fi + dx[i];
            int y = top.se + dy[i];
            if(1 <= x && x <= n && 1 <= y && y <= n && a[x][y]!='T' && d[x][y] > d[top.fi][top.se] + 1){
                d[x][y] = d[top.fi][top.se] + 1;
                int diff = d[x][y] - ti - 1;
                diff /= s;
                diff += ti + 1;
                if(diff <= d1[x][y])
                    q.push(mp(x, y));
            }
        }
    }
}

void process(){
    bfs_multi_source();
    int l = 0, r = n*n + 1, res = -1;
    while(l <= r){
        int mid = (l + r) >> 1;
        bfs(st.fi, st.se, mid);
        if(d[e.fi][e.se]==inf)
            r = mid - 1;
        else{
            res = mid;
            l = mid + 1;
        }
    }
    cout << res;
}

int main() {
//    readfile();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    TC(t){
        inp();
        process();
//    }
    return 0;
}

Compilation message

mecho.cpp: In function 'void readfile()':
mecho.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen("text.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 316 KB Output isn't correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 101 ms 6168 KB Output is correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Incorrect 1 ms 716 KB Output isn't correct
13 Incorrect 1 ms 576 KB Output isn't correct
14 Correct 1 ms 704 KB Output is correct
15 Incorrect 1 ms 456 KB Output isn't correct
16 Correct 0 ms 436 KB Output is correct
17 Incorrect 1 ms 424 KB Output isn't correct
18 Correct 1 ms 440 KB Output is correct
19 Incorrect 1 ms 460 KB Output isn't correct
20 Correct 1 ms 460 KB Output is correct
21 Incorrect 1 ms 556 KB Output isn't correct
22 Correct 1 ms 568 KB Output is correct
23 Incorrect 1 ms 576 KB Output isn't correct
24 Correct 1 ms 556 KB Output is correct
25 Incorrect 1 ms 684 KB Output isn't correct
26 Correct 1 ms 716 KB Output is correct
27 Incorrect 1 ms 688 KB Output isn't correct
28 Correct 1 ms 708 KB Output is correct
29 Incorrect 1 ms 840 KB Output isn't correct
30 Correct 1 ms 836 KB Output is correct
31 Incorrect 1 ms 844 KB Output isn't correct
32 Correct 1 ms 836 KB Output is correct
33 Incorrect 8 ms 2784 KB Output isn't correct
34 Correct 7 ms 2756 KB Output is correct
35 Correct 23 ms 2856 KB Output is correct
36 Incorrect 8 ms 3220 KB Output isn't correct
37 Correct 10 ms 3144 KB Output is correct
38 Correct 27 ms 3224 KB Output is correct
39 Incorrect 14 ms 3524 KB Output isn't correct
40 Correct 13 ms 3572 KB Output is correct
41 Correct 60 ms 3576 KB Output is correct
42 Incorrect 11 ms 3932 KB Output isn't correct
43 Correct 12 ms 3900 KB Output is correct
44 Correct 46 ms 3904 KB Output is correct
45 Incorrect 12 ms 4272 KB Output isn't correct
46 Correct 14 ms 4296 KB Output is correct
47 Correct 59 ms 4296 KB Output is correct
48 Incorrect 15 ms 4556 KB Output isn't correct
49 Correct 23 ms 4592 KB Output is correct
50 Correct 67 ms 4640 KB Output is correct
51 Incorrect 18 ms 5008 KB Output isn't correct
52 Correct 21 ms 4940 KB Output is correct
53 Correct 88 ms 4992 KB Output is correct
54 Incorrect 23 ms 5328 KB Output isn't correct
55 Correct 26 ms 5348 KB Output is correct
56 Correct 105 ms 5352 KB Output is correct
57 Incorrect 39 ms 5636 KB Output isn't correct
58 Correct 34 ms 5648 KB Output is correct
59 Correct 104 ms 5692 KB Output is correct
60 Incorrect 27 ms 5956 KB Output isn't correct
61 Correct 55 ms 5992 KB Output is correct
62 Correct 140 ms 6064 KB Output is correct
63 Correct 99 ms 6056 KB Output is correct
64 Correct 270 ms 6052 KB Output is correct
65 Correct 173 ms 5940 KB Output is correct
66 Incorrect 130 ms 6056 KB Output isn't correct
67 Correct 112 ms 6056 KB Output is correct
68 Correct 73 ms 6084 KB Output is correct
69 Correct 51 ms 6056 KB Output is correct
70 Correct 38 ms 5972 KB Output is correct
71 Correct 48 ms 6012 KB Output is correct
72 Incorrect 37 ms 6084 KB Output isn't correct
73 Incorrect 47 ms 6328 KB Output isn't correct
74 Correct 61 ms 6260 KB Output is correct
75 Correct 84 ms 6336 KB Output is correct
76 Correct 82 ms 6308 KB Output is correct
77 Correct 66 ms 6336 KB Output is correct
78 Correct 95 ms 6220 KB Output is correct
79 Correct 53 ms 6308 KB Output is correct
80 Correct 57 ms 6224 KB Output is correct
81 Correct 91 ms 6308 KB Output is correct
82 Correct 60 ms 6304 KB Output is correct
83 Correct 92 ms 6176 KB Output is correct
84 Correct 90 ms 6228 KB Output is correct
85 Correct 118 ms 6268 KB Output is correct
86 Correct 75 ms 6216 KB Output is correct
87 Correct 99 ms 6272 KB Output is correct
88 Correct 101 ms 6216 KB Output is correct
89 Correct 89 ms 6212 KB Output is correct
90 Correct 88 ms 6212 KB Output is correct
91 Correct 101 ms 6132 KB Output is correct
92 Correct 120 ms 6216 KB Output is correct