Submission #955406

# Submission time Handle Problem Language Result Execution time Memory
955406 2024-03-30T10:56:40 Z Otalp Maze (JOI23_ho_t3) C++14
59 / 100
2000 ms 218272 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(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 604 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 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 63 ms 8528 KB Output is correct
20 Correct 20 ms 5592 KB Output is correct
21 Correct 37 ms 8536 KB Output is correct
22 Correct 48 ms 8532 KB Output is correct
23 Correct 56 ms 8612 KB Output is correct
24 Correct 14 ms 7128 KB Output is correct
25 Correct 27 ms 7132 KB Output is correct
26 Correct 45 ms 8532 KB Output is correct
27 Correct 47 ms 8528 KB Output is correct
28 Correct 52 ms 8532 KB Output is correct
29 Correct 165 ms 21648 KB Output is correct
30 Correct 29 ms 8180 KB Output is correct
31 Correct 97 ms 21468 KB Output is correct
32 Correct 131 ms 21528 KB Output is correct
33 Correct 163 ms 21788 KB Output is correct
34 Correct 41 ms 16848 KB Output is correct
35 Correct 71 ms 16696 KB Output is correct
36 Correct 129 ms 21600 KB Output is correct
37 Correct 130 ms 21584 KB Output is correct
38 Correct 140 ms 21396 KB Output is correct
39 Execution timed out 2067 ms 214836 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 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 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 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 600 KB Output is correct
8 Correct 1 ms 604 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 600 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 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 34 ms 5800 KB Output is correct
26 Correct 36 ms 8276 KB Output is correct
27 Correct 34 ms 8708 KB Output is correct
28 Correct 36 ms 8540 KB Output is correct
29 Correct 38 ms 8664 KB Output is correct
30 Correct 35 ms 8528 KB Output is correct
31 Correct 37 ms 8528 KB Output is correct
32 Correct 47 ms 8680 KB Output is correct
33 Correct 49 ms 8692 KB Output is correct
34 Correct 124 ms 18076 KB Output is correct
35 Correct 99 ms 21392 KB Output is correct
36 Correct 95 ms 21504 KB Output is correct
37 Correct 106 ms 21448 KB Output is correct
38 Correct 96 ms 21460 KB Output is correct
39 Correct 483 ms 62212 KB Output is correct
40 Correct 1401 ms 175624 KB Output is correct
41 Correct 1366 ms 218096 KB Output is correct
42 Correct 1365 ms 218024 KB Output is correct
43 Correct 1275 ms 217952 KB Output is correct
44 Correct 1288 ms 218272 KB Output is correct
45 Correct 1331 ms 206972 KB Output is correct
46 Correct 1407 ms 207448 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 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 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 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 56 ms 8580 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 856 KB Output is correct
36 Correct 34 ms 5824 KB Output is correct
37 Correct 20 ms 5596 KB Output is correct
38 Correct 37 ms 8020 KB Output is correct
39 Correct 39 ms 8540 KB Output is correct
40 Correct 48 ms 8608 KB Output is correct
41 Correct 63 ms 8528 KB Output is correct
42 Correct 33 ms 8684 KB Output is correct
43 Correct 35 ms 8696 KB Output is correct
44 Correct 34 ms 8532 KB Output is correct
45 Correct 14 ms 6876 KB Output is correct
46 Correct 27 ms 6972 KB Output is correct
47 Correct 28 ms 7740 KB Output is correct
48 Correct 36 ms 8404 KB Output is correct
49 Correct 37 ms 8884 KB Output is correct
50 Correct 41 ms 8784 KB Output is correct
51 Correct 38 ms 8528 KB Output is correct
52 Correct 45 ms 8532 KB Output is correct
53 Correct 47 ms 8684 KB Output is correct
54 Correct 52 ms 8684 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 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 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 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 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 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 56 ms 8580 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 856 KB Output is correct
36 Correct 34 ms 5824 KB Output is correct
37 Correct 20 ms 5596 KB Output is correct
38 Correct 37 ms 8020 KB Output is correct
39 Correct 39 ms 8540 KB Output is correct
40 Correct 48 ms 8608 KB Output is correct
41 Correct 63 ms 8528 KB Output is correct
42 Correct 33 ms 8684 KB Output is correct
43 Correct 35 ms 8696 KB Output is correct
44 Correct 34 ms 8532 KB Output is correct
45 Correct 14 ms 6876 KB Output is correct
46 Correct 27 ms 6972 KB Output is correct
47 Correct 28 ms 7740 KB Output is correct
48 Correct 36 ms 8404 KB Output is correct
49 Correct 37 ms 8884 KB Output is correct
50 Correct 41 ms 8784 KB Output is correct
51 Correct 38 ms 8528 KB Output is correct
52 Correct 45 ms 8532 KB Output is correct
53 Correct 47 ms 8684 KB Output is correct
54 Correct 52 ms 8684 KB Output is correct
55 Correct 168 ms 21392 KB Output is correct
56 Correct 32 ms 7988 KB Output is correct
57 Correct 114 ms 17952 KB Output is correct
58 Correct 117 ms 19116 KB Output is correct
59 Correct 95 ms 21584 KB Output is correct
60 Correct 131 ms 21368 KB Output is correct
61 Correct 165 ms 21364 KB Output is correct
62 Correct 97 ms 21632 KB Output is correct
63 Correct 101 ms 21528 KB Output is correct
64 Correct 103 ms 21544 KB Output is correct
65 Correct 37 ms 16700 KB Output is correct
66 Correct 71 ms 16692 KB Output is correct
67 Correct 75 ms 18912 KB Output is correct
68 Correct 99 ms 20936 KB Output is correct
69 Correct 97 ms 21344 KB Output is correct
70 Correct 101 ms 21532 KB Output is correct
71 Correct 106 ms 21136 KB Output is correct
72 Correct 127 ms 21596 KB Output is correct
73 Correct 132 ms 21592 KB Output is correct
74 Correct 144 ms 21596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 604 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 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 63 ms 8528 KB Output is correct
20 Correct 20 ms 5592 KB Output is correct
21 Correct 37 ms 8536 KB Output is correct
22 Correct 48 ms 8532 KB Output is correct
23 Correct 56 ms 8612 KB Output is correct
24 Correct 14 ms 7128 KB Output is correct
25 Correct 27 ms 7132 KB Output is correct
26 Correct 45 ms 8532 KB Output is correct
27 Correct 47 ms 8528 KB Output is correct
28 Correct 52 ms 8532 KB Output is correct
29 Correct 165 ms 21648 KB Output is correct
30 Correct 29 ms 8180 KB Output is correct
31 Correct 97 ms 21468 KB Output is correct
32 Correct 131 ms 21528 KB Output is correct
33 Correct 163 ms 21788 KB Output is correct
34 Correct 41 ms 16848 KB Output is correct
35 Correct 71 ms 16696 KB Output is correct
36 Correct 129 ms 21600 KB Output is correct
37 Correct 130 ms 21584 KB Output is correct
38 Correct 140 ms 21396 KB Output is correct
39 Execution timed out 2067 ms 214836 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 604 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 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 63 ms 8528 KB Output is correct
20 Correct 20 ms 5592 KB Output is correct
21 Correct 37 ms 8536 KB Output is correct
22 Correct 48 ms 8532 KB Output is correct
23 Correct 56 ms 8612 KB Output is correct
24 Correct 14 ms 7128 KB Output is correct
25 Correct 27 ms 7132 KB Output is correct
26 Correct 45 ms 8532 KB Output is correct
27 Correct 47 ms 8528 KB Output is correct
28 Correct 52 ms 8532 KB Output is correct
29 Correct 165 ms 21648 KB Output is correct
30 Correct 29 ms 8180 KB Output is correct
31 Correct 97 ms 21468 KB Output is correct
32 Correct 131 ms 21528 KB Output is correct
33 Correct 163 ms 21788 KB Output is correct
34 Correct 41 ms 16848 KB Output is correct
35 Correct 71 ms 16696 KB Output is correct
36 Correct 129 ms 21600 KB Output is correct
37 Correct 130 ms 21584 KB Output is correct
38 Correct 140 ms 21396 KB Output is correct
39 Execution timed out 2067 ms 214836 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 604 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 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 63 ms 8528 KB Output is correct
20 Correct 20 ms 5592 KB Output is correct
21 Correct 37 ms 8536 KB Output is correct
22 Correct 48 ms 8532 KB Output is correct
23 Correct 56 ms 8612 KB Output is correct
24 Correct 14 ms 7128 KB Output is correct
25 Correct 27 ms 7132 KB Output is correct
26 Correct 45 ms 8532 KB Output is correct
27 Correct 47 ms 8528 KB Output is correct
28 Correct 52 ms 8532 KB Output is correct
29 Correct 165 ms 21648 KB Output is correct
30 Correct 29 ms 8180 KB Output is correct
31 Correct 97 ms 21468 KB Output is correct
32 Correct 131 ms 21528 KB Output is correct
33 Correct 163 ms 21788 KB Output is correct
34 Correct 41 ms 16848 KB Output is correct
35 Correct 71 ms 16696 KB Output is correct
36 Correct 129 ms 21600 KB Output is correct
37 Correct 130 ms 21584 KB Output is correct
38 Correct 140 ms 21396 KB Output is correct
39 Execution timed out 2067 ms 214836 KB Time limit exceeded
40 Halted 0 ms 0 KB -