Submission #955195

# Submission time Handle Problem Language Result Execution time Memory
955195 2024-03-29T16:02:08 Z Otalp Maze (JOI23_ho_t3) C++14
43 / 100
2000 ms 177400 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<pair<pii, int>> h;
    h.pb({s, 0});
    while(h.size()){
        int x=h[0].ff.ff, y=h[0].ff.ss;
        if(us[x][y]){
            h.pop_front();
            continue;
        }
        dp[x][y] = h[0].ss;
        us[x][y] = 1;
        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) h.push_front({{x + d.ff, y + d.ss}, dp[x][y]});
                else{
                    if(dp[x][y] >= m / k + n / k + 2){
                        h.push_front({{x + d.ff, y + d.ff}, dp[x][y]});
                        continue;
                    }
                    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)));
                    if(g < dp[x][y]) h.push_front({{x + d.ff, y + d.ss}, g + 1});
                    else h.pb({{x + d.ff, y + d.ss}, g + 1});
                    //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 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 0 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 0 ms 348 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 81 ms 8500 KB Output is correct
20 Correct 22 ms 5596 KB Output is correct
21 Correct 38 ms 9156 KB Output is correct
22 Correct 72 ms 8784 KB Output is correct
23 Correct 80 ms 8676 KB Output is correct
24 Correct 16 ms 6872 KB Output is correct
25 Correct 29 ms 6868 KB Output is correct
26 Correct 67 ms 8524 KB Output is correct
27 Correct 72 ms 8628 KB Output is correct
28 Correct 82 ms 8680 KB Output is correct
29 Correct 233 ms 21516 KB Output is correct
30 Correct 42 ms 7948 KB Output is correct
31 Correct 108 ms 23124 KB Output is correct
32 Correct 198 ms 21508 KB Output is correct
33 Correct 251 ms 21504 KB Output is correct
34 Correct 44 ms 16676 KB Output is correct
35 Correct 74 ms 16716 KB Output is correct
36 Correct 191 ms 21392 KB Output is correct
37 Correct 211 ms 21476 KB Output is correct
38 Correct 207 ms 21332 KB Output is correct
39 Execution timed out 2054 ms 162480 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 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 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 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 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 1 ms 348 KB Output is correct
19 Correct 1 ms 500 KB Output is correct
20 Correct 1 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 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 600 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 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 604 KB Output is correct
12 Correct 0 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 348 KB Output is correct
17 Correct 0 ms 348 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 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 2 ms 604 KB Output is correct
25 Correct 57 ms 6104 KB Output is correct
26 Correct 56 ms 8272 KB Output is correct
27 Correct 38 ms 9236 KB Output is correct
28 Correct 40 ms 9176 KB Output is correct
29 Correct 39 ms 9308 KB Output is correct
30 Correct 36 ms 9368 KB Output is correct
31 Correct 46 ms 8536 KB Output is correct
32 Correct 67 ms 8532 KB Output is correct
33 Correct 70 ms 8552 KB Output is correct
34 Correct 182 ms 18024 KB Output is correct
35 Correct 105 ms 23120 KB Output is correct
36 Correct 104 ms 22908 KB Output is correct
37 Correct 103 ms 23376 KB Output is correct
38 Correct 102 ms 23368 KB Output is correct
39 Correct 861 ms 62656 KB Output is correct
40 Execution timed out 2058 ms 177400 KB Time limit exceeded
41 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 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 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 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 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 1 ms 348 KB Output is correct
19 Correct 1 ms 500 KB Output is correct
20 Correct 1 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 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 600 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 80 ms 8576 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 3 ms 860 KB Output is correct
36 Correct 52 ms 5712 KB Output is correct
37 Correct 22 ms 5596 KB Output is correct
38 Correct 56 ms 8276 KB Output is correct
39 Correct 38 ms 9048 KB Output is correct
40 Correct 70 ms 8528 KB Output is correct
41 Correct 79 ms 8444 KB Output is correct
42 Correct 36 ms 9308 KB Output is correct
43 Correct 37 ms 9396 KB Output is correct
44 Correct 36 ms 9168 KB Output is correct
45 Correct 15 ms 6872 KB Output is correct
46 Correct 28 ms 6868 KB Output is correct
47 Correct 37 ms 7812 KB Output is correct
48 Correct 52 ms 8388 KB Output is correct
49 Correct 47 ms 9036 KB Output is correct
50 Correct 48 ms 8784 KB Output is correct
51 Correct 49 ms 8528 KB Output is correct
52 Correct 66 ms 8532 KB Output is correct
53 Correct 72 ms 8784 KB Output is correct
54 Correct 74 ms 8532 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 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 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 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 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 1 ms 348 KB Output is correct
19 Correct 1 ms 500 KB Output is correct
20 Correct 1 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 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 600 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 80 ms 8576 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 3 ms 860 KB Output is correct
36 Correct 52 ms 5712 KB Output is correct
37 Correct 22 ms 5596 KB Output is correct
38 Correct 56 ms 8276 KB Output is correct
39 Correct 38 ms 9048 KB Output is correct
40 Correct 70 ms 8528 KB Output is correct
41 Correct 79 ms 8444 KB Output is correct
42 Correct 36 ms 9308 KB Output is correct
43 Correct 37 ms 9396 KB Output is correct
44 Correct 36 ms 9168 KB Output is correct
45 Correct 15 ms 6872 KB Output is correct
46 Correct 28 ms 6868 KB Output is correct
47 Correct 37 ms 7812 KB Output is correct
48 Correct 52 ms 8388 KB Output is correct
49 Correct 47 ms 9036 KB Output is correct
50 Correct 48 ms 8784 KB Output is correct
51 Correct 49 ms 8528 KB Output is correct
52 Correct 66 ms 8532 KB Output is correct
53 Correct 72 ms 8784 KB Output is correct
54 Correct 74 ms 8532 KB Output is correct
55 Correct 218 ms 21332 KB Output is correct
56 Correct 39 ms 7820 KB Output is correct
57 Correct 183 ms 18000 KB Output is correct
58 Correct 175 ms 19284 KB Output is correct
59 Correct 113 ms 23124 KB Output is correct
60 Correct 196 ms 22012 KB Output is correct
61 Correct 224 ms 21584 KB Output is correct
62 Correct 103 ms 23000 KB Output is correct
63 Correct 105 ms 23260 KB Output is correct
64 Correct 103 ms 23296 KB Output is correct
65 Correct 41 ms 16900 KB Output is correct
66 Correct 74 ms 16696 KB Output is correct
67 Correct 98 ms 18900 KB Output is correct
68 Correct 120 ms 21076 KB Output is correct
69 Correct 122 ms 21528 KB Output is correct
70 Correct 125 ms 21584 KB Output is correct
71 Correct 128 ms 21072 KB Output is correct
72 Correct 183 ms 21588 KB Output is correct
73 Correct 192 ms 21336 KB Output is correct
74 Correct 202 ms 21332 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 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 0 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 0 ms 348 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 81 ms 8500 KB Output is correct
20 Correct 22 ms 5596 KB Output is correct
21 Correct 38 ms 9156 KB Output is correct
22 Correct 72 ms 8784 KB Output is correct
23 Correct 80 ms 8676 KB Output is correct
24 Correct 16 ms 6872 KB Output is correct
25 Correct 29 ms 6868 KB Output is correct
26 Correct 67 ms 8524 KB Output is correct
27 Correct 72 ms 8628 KB Output is correct
28 Correct 82 ms 8680 KB Output is correct
29 Correct 233 ms 21516 KB Output is correct
30 Correct 42 ms 7948 KB Output is correct
31 Correct 108 ms 23124 KB Output is correct
32 Correct 198 ms 21508 KB Output is correct
33 Correct 251 ms 21504 KB Output is correct
34 Correct 44 ms 16676 KB Output is correct
35 Correct 74 ms 16716 KB Output is correct
36 Correct 191 ms 21392 KB Output is correct
37 Correct 211 ms 21476 KB Output is correct
38 Correct 207 ms 21332 KB Output is correct
39 Execution timed out 2054 ms 162480 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 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 0 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 0 ms 348 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 81 ms 8500 KB Output is correct
20 Correct 22 ms 5596 KB Output is correct
21 Correct 38 ms 9156 KB Output is correct
22 Correct 72 ms 8784 KB Output is correct
23 Correct 80 ms 8676 KB Output is correct
24 Correct 16 ms 6872 KB Output is correct
25 Correct 29 ms 6868 KB Output is correct
26 Correct 67 ms 8524 KB Output is correct
27 Correct 72 ms 8628 KB Output is correct
28 Correct 82 ms 8680 KB Output is correct
29 Correct 233 ms 21516 KB Output is correct
30 Correct 42 ms 7948 KB Output is correct
31 Correct 108 ms 23124 KB Output is correct
32 Correct 198 ms 21508 KB Output is correct
33 Correct 251 ms 21504 KB Output is correct
34 Correct 44 ms 16676 KB Output is correct
35 Correct 74 ms 16716 KB Output is correct
36 Correct 191 ms 21392 KB Output is correct
37 Correct 211 ms 21476 KB Output is correct
38 Correct 207 ms 21332 KB Output is correct
39 Execution timed out 2054 ms 162480 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 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 0 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 0 ms 348 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 81 ms 8500 KB Output is correct
20 Correct 22 ms 5596 KB Output is correct
21 Correct 38 ms 9156 KB Output is correct
22 Correct 72 ms 8784 KB Output is correct
23 Correct 80 ms 8676 KB Output is correct
24 Correct 16 ms 6872 KB Output is correct
25 Correct 29 ms 6868 KB Output is correct
26 Correct 67 ms 8524 KB Output is correct
27 Correct 72 ms 8628 KB Output is correct
28 Correct 82 ms 8680 KB Output is correct
29 Correct 233 ms 21516 KB Output is correct
30 Correct 42 ms 7948 KB Output is correct
31 Correct 108 ms 23124 KB Output is correct
32 Correct 198 ms 21508 KB Output is correct
33 Correct 251 ms 21504 KB Output is correct
34 Correct 44 ms 16676 KB Output is correct
35 Correct 74 ms 16716 KB Output is correct
36 Correct 191 ms 21392 KB Output is correct
37 Correct 211 ms 21476 KB Output is correct
38 Correct 207 ms 21332 KB Output is correct
39 Execution timed out 2054 ms 162480 KB Time limit exceeded
40 Halted 0 ms 0 KB -