Submission #955404

# Submission time Handle Problem Language Result Execution time Memory
955404 2024-03-30T10:54:23 Z Otalp Maze (JOI23_ho_t3) C++14
59 / 100
2000 ms 219628 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
 
 
int n, m, k;
vector<vector<int> > a, dp, us;
struct node{
    int x=1e9;
    node *l=nullptr, *r=nullptr;
    node(){}
};
 
 
void dupd(node *v, int l, int r, int pos, int x){
    if(l == r){
        v -> x = min(x, v -> x);
        return;
    }
    int mid=(l+r)/2;
    if(mid >= pos){
        if(!v -> l) v -> l = new node();
        dupd(v -> l, l, mid, pos, x);
    }
    else{
        if(!v -> r) v -> r = new node();
        dupd(v -> r, mid + 1, r, pos, x);
    }
    v -> x = min((v->l ?v -> l -> x :(int)1e9), (v -> r ? v->r->x :(int)1e9));
}
 
int dget(node *v, int l, int r, int L, int R){
    if(v == nullptr) return 1e9;
    if(r < L or R < l){
        return 1e9;
    }
    if(L <= l and r <= R){
        return v -> x;
    }
    int mid=(l+r)/2;
    return min(dget(v -> l, l, mid, L, R), dget(v -> r, mid+1, r, L, R));
}
 
vector<node*> t;
 
void upd(int v, int l, int r, int L, int R, int x){
    dupd(t[v], 1, m, R, x);
    if(l == r){
        return;
    }
    int mid = (l + r)/2;
    if(mid >= L){
        upd(v+v, l, mid, L, R, x);
    }
    else{
        upd(v+v+1, mid+1, r, L, R, x); 
    }
}
 
 
int get(int v, int l, int r, int lx, int rx, int ly, int ry){
    if(rx < l or r < lx){
        return 1e9;
    }
    if(lx <= l and r <= rx){
        return dget(t[v], 1, m, ly, ry); 
    }
    int mid=(l+r)/2;
    return min(get(v+v, l, mid, lx, rx, ly, ry), get(v+v+1, mid+1, r, lx, rx, ly, ry));
}
 
void solve(){
    cin>>n>>m>>k;
    pii s, g;
    cin>>s.ff>>s.ss;
    cin>>g.ff>>g.ss;
    for(int i=0; i<=4 * n+100; i++){
        t.pb(new node());
    }
    for(int i=0; i<=n + 2; i++){
        us.pb({});
        dp.pb({});
        a.pb({});
        for(int j=0; j<=m + 2; j++){
            dp[i].pb(0);
            us[i].pb(0);
            a[i].pb(0);
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            char c;
            cin>>c;
            if(c == '#') a[i][j] = 1;
            else a[i][j] = 0;
        }
    }
    vector<pii> nap = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    deque<pii> h;
    h.pb(s);
    us[s.ff][s.ss] = 1;
    dp[s.ff][s.ss] = 0;
    while(h.size()){
        int x=h[0].ff, y=h[0].ss;
        upd(1, 1, n, x, y, dp[x][y]);
        h.pop_front();
        for(pii d: nap){
            if(!us[x + d.ff][y + d.ss] and x + d.ff <= n and x + d.ff >= 1 and y + d.ss <= m and y + d.ss >= 1){
                if(a[x + d.ff][y + d.ss] == 0){ 
                    dp[x + d.ff][y + d.ss] = dp[x][y];
                    us[x + d.ff][y + d.ss] = 1;
                    h.push_front({x + d.ff, y + d.ss});
                }
                else{
                    int g = get(1, 1, n, max(1, x+d.ff-k), min(n, x+d.ff+k), max(1, y+d.ss-k+1), min(m, y+d.ss+k-1));
                    g = min(g, get(1, 1, n, max(1, x+d.ff-k+1), min(n, x+d.ff+k-1), max(1, y+d.ss-k), min(m, y+d.ss+k)));
                    dp[x + d.ff][y + d.ss] = g + 1;
                    us[x + d.ff][y + d.ss] = 1;
                    if(g < dp[x][y]) h.push_front({x + d.ff, y + d.ss});
                    else h.pb({x + d.ff, y + d.ss});
                    //cout<<x<<' '<<y<<' '<<x+d.ff<<' '<<y + d.ss<<' '<<max(1, x+d.ff-k)<<' '<<min(n, x+d.ff+k)<<' '<<max(1, y+d.ss-k+1)<<' '<<min(m, y+d.ss+k-1)<<' '<<'\n';
                }
                continue;
            }
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            //cout<<dp[i][j]<<' ';
        }
        //cout<<'\n';
    }
    cout<<dp[g.ff][g.ss];
}   
 
 
int main(){
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 65 ms 8652 KB Output is correct
20 Correct 21 ms 5592 KB Output is correct
21 Correct 42 ms 8540 KB Output is correct
22 Correct 54 ms 8736 KB Output is correct
23 Correct 66 ms 8532 KB Output is correct
24 Correct 16 ms 6972 KB Output is correct
25 Correct 28 ms 7124 KB Output is correct
26 Correct 51 ms 8608 KB Output is correct
27 Correct 48 ms 8528 KB Output is correct
28 Correct 52 ms 8676 KB Output is correct
29 Correct 161 ms 21592 KB Output is correct
30 Correct 34 ms 7984 KB Output is correct
31 Correct 115 ms 21608 KB Output is correct
32 Correct 151 ms 21592 KB Output is correct
33 Correct 172 ms 21480 KB Output is correct
34 Correct 40 ms 17212 KB Output is correct
35 Correct 73 ms 16892 KB Output is correct
36 Correct 127 ms 21668 KB Output is correct
37 Correct 136 ms 21512 KB Output is correct
38 Correct 150 ms 21588 KB Output is correct
39 Execution timed out 2049 ms 210232 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 460 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 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 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 436 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 35 ms 5748 KB Output is correct
26 Correct 38 ms 8052 KB Output is correct
27 Correct 35 ms 8528 KB Output is correct
28 Correct 35 ms 8532 KB Output is correct
29 Correct 39 ms 8632 KB Output is correct
30 Correct 35 ms 8528 KB Output is correct
31 Correct 45 ms 8536 KB Output is correct
32 Correct 46 ms 8712 KB Output is correct
33 Correct 49 ms 8672 KB Output is correct
34 Correct 109 ms 18004 KB Output is correct
35 Correct 106 ms 21588 KB Output is correct
36 Correct 101 ms 21700 KB Output is correct
37 Correct 103 ms 21592 KB Output is correct
38 Correct 99 ms 21640 KB Output is correct
39 Correct 497 ms 62504 KB Output is correct
40 Correct 1407 ms 177100 KB Output is correct
41 Correct 1341 ms 219564 KB Output is correct
42 Correct 1331 ms 219592 KB Output is correct
43 Correct 1330 ms 219616 KB Output is correct
44 Correct 1338 ms 219628 KB Output is correct
45 Correct 1344 ms 207588 KB Output is correct
46 Correct 1412 ms 208632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 460 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 63 ms 8532 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 860 KB Output is correct
36 Correct 35 ms 5972 KB Output is correct
37 Correct 21 ms 5584 KB Output is correct
38 Correct 45 ms 8236 KB Output is correct
39 Correct 37 ms 8744 KB Output is correct
40 Correct 51 ms 8732 KB Output is correct
41 Correct 62 ms 8532 KB Output is correct
42 Correct 36 ms 8528 KB Output is correct
43 Correct 45 ms 8792 KB Output is correct
44 Correct 38 ms 8532 KB Output is correct
45 Correct 15 ms 7128 KB Output is correct
46 Correct 28 ms 7076 KB Output is correct
47 Correct 29 ms 7740 KB Output is correct
48 Correct 37 ms 8516 KB Output is correct
49 Correct 39 ms 9088 KB Output is correct
50 Correct 42 ms 8788 KB Output is correct
51 Correct 39 ms 8524 KB Output is correct
52 Correct 47 ms 8512 KB Output is correct
53 Correct 49 ms 8708 KB Output is correct
54 Correct 51 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 460 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 63 ms 8532 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 860 KB Output is correct
36 Correct 35 ms 5972 KB Output is correct
37 Correct 21 ms 5584 KB Output is correct
38 Correct 45 ms 8236 KB Output is correct
39 Correct 37 ms 8744 KB Output is correct
40 Correct 51 ms 8732 KB Output is correct
41 Correct 62 ms 8532 KB Output is correct
42 Correct 36 ms 8528 KB Output is correct
43 Correct 45 ms 8792 KB Output is correct
44 Correct 38 ms 8532 KB Output is correct
45 Correct 15 ms 7128 KB Output is correct
46 Correct 28 ms 7076 KB Output is correct
47 Correct 29 ms 7740 KB Output is correct
48 Correct 37 ms 8516 KB Output is correct
49 Correct 39 ms 9088 KB Output is correct
50 Correct 42 ms 8788 KB Output is correct
51 Correct 39 ms 8524 KB Output is correct
52 Correct 47 ms 8512 KB Output is correct
53 Correct 49 ms 8708 KB Output is correct
54 Correct 51 ms 8528 KB Output is correct
55 Correct 160 ms 21520 KB Output is correct
56 Correct 31 ms 7996 KB Output is correct
57 Correct 109 ms 17952 KB Output is correct
58 Correct 122 ms 19308 KB Output is correct
59 Correct 109 ms 21820 KB Output is correct
60 Correct 139 ms 21600 KB Output is correct
61 Correct 171 ms 21496 KB Output is correct
62 Correct 106 ms 21652 KB Output is correct
63 Correct 109 ms 21572 KB Output is correct
64 Correct 102 ms 21624 KB Output is correct
65 Correct 40 ms 16940 KB Output is correct
66 Correct 74 ms 16956 KB Output is correct
67 Correct 88 ms 19008 KB Output is correct
68 Correct 100 ms 21080 KB Output is correct
69 Correct 102 ms 21588 KB Output is correct
70 Correct 106 ms 21588 KB Output is correct
71 Correct 112 ms 21332 KB Output is correct
72 Correct 124 ms 21624 KB Output is correct
73 Correct 135 ms 21584 KB Output is correct
74 Correct 154 ms 21716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 65 ms 8652 KB Output is correct
20 Correct 21 ms 5592 KB Output is correct
21 Correct 42 ms 8540 KB Output is correct
22 Correct 54 ms 8736 KB Output is correct
23 Correct 66 ms 8532 KB Output is correct
24 Correct 16 ms 6972 KB Output is correct
25 Correct 28 ms 7124 KB Output is correct
26 Correct 51 ms 8608 KB Output is correct
27 Correct 48 ms 8528 KB Output is correct
28 Correct 52 ms 8676 KB Output is correct
29 Correct 161 ms 21592 KB Output is correct
30 Correct 34 ms 7984 KB Output is correct
31 Correct 115 ms 21608 KB Output is correct
32 Correct 151 ms 21592 KB Output is correct
33 Correct 172 ms 21480 KB Output is correct
34 Correct 40 ms 17212 KB Output is correct
35 Correct 73 ms 16892 KB Output is correct
36 Correct 127 ms 21668 KB Output is correct
37 Correct 136 ms 21512 KB Output is correct
38 Correct 150 ms 21588 KB Output is correct
39 Execution timed out 2049 ms 210232 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 65 ms 8652 KB Output is correct
20 Correct 21 ms 5592 KB Output is correct
21 Correct 42 ms 8540 KB Output is correct
22 Correct 54 ms 8736 KB Output is correct
23 Correct 66 ms 8532 KB Output is correct
24 Correct 16 ms 6972 KB Output is correct
25 Correct 28 ms 7124 KB Output is correct
26 Correct 51 ms 8608 KB Output is correct
27 Correct 48 ms 8528 KB Output is correct
28 Correct 52 ms 8676 KB Output is correct
29 Correct 161 ms 21592 KB Output is correct
30 Correct 34 ms 7984 KB Output is correct
31 Correct 115 ms 21608 KB Output is correct
32 Correct 151 ms 21592 KB Output is correct
33 Correct 172 ms 21480 KB Output is correct
34 Correct 40 ms 17212 KB Output is correct
35 Correct 73 ms 16892 KB Output is correct
36 Correct 127 ms 21668 KB Output is correct
37 Correct 136 ms 21512 KB Output is correct
38 Correct 150 ms 21588 KB Output is correct
39 Execution timed out 2049 ms 210232 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 65 ms 8652 KB Output is correct
20 Correct 21 ms 5592 KB Output is correct
21 Correct 42 ms 8540 KB Output is correct
22 Correct 54 ms 8736 KB Output is correct
23 Correct 66 ms 8532 KB Output is correct
24 Correct 16 ms 6972 KB Output is correct
25 Correct 28 ms 7124 KB Output is correct
26 Correct 51 ms 8608 KB Output is correct
27 Correct 48 ms 8528 KB Output is correct
28 Correct 52 ms 8676 KB Output is correct
29 Correct 161 ms 21592 KB Output is correct
30 Correct 34 ms 7984 KB Output is correct
31 Correct 115 ms 21608 KB Output is correct
32 Correct 151 ms 21592 KB Output is correct
33 Correct 172 ms 21480 KB Output is correct
34 Correct 40 ms 17212 KB Output is correct
35 Correct 73 ms 16892 KB Output is correct
36 Correct 127 ms 21668 KB Output is correct
37 Correct 136 ms 21512 KB Output is correct
38 Correct 150 ms 21588 KB Output is correct
39 Execution timed out 2049 ms 210232 KB Time limit exceeded
40 Halted 0 ms 0 KB -