답안 #955190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955190 2024-03-29T15:44:08 Z Otalp Maze (JOI23_ho_t3) C++14
43 / 100
2000 ms 178076 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{
                    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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 432 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 600 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 432 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 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 81 ms 8664 KB Output is correct
20 Correct 23 ms 5596 KB Output is correct
21 Correct 46 ms 9288 KB Output is correct
22 Correct 70 ms 8528 KB Output is correct
23 Correct 85 ms 8652 KB Output is correct
24 Correct 15 ms 7128 KB Output is correct
25 Correct 28 ms 6908 KB Output is correct
26 Correct 69 ms 8592 KB Output is correct
27 Correct 70 ms 8532 KB Output is correct
28 Correct 73 ms 8504 KB Output is correct
29 Correct 226 ms 21728 KB Output is correct
30 Correct 38 ms 7984 KB Output is correct
31 Correct 107 ms 23120 KB Output is correct
32 Correct 205 ms 21668 KB Output is correct
33 Correct 224 ms 21560 KB Output is correct
34 Correct 40 ms 16976 KB Output is correct
35 Correct 73 ms 16952 KB Output is correct
36 Correct 181 ms 21532 KB Output is correct
37 Correct 189 ms 21492 KB Output is correct
38 Correct 201 ms 21604 KB Output is correct
39 Execution timed out 2060 ms 169836 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 2 ms 604 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 440 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 436 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 436 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 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 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 2 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 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 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 344 KB Output is correct
15 Correct 0 ms 344 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 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 51 ms 5968 KB Output is correct
26 Correct 63 ms 8344 KB Output is correct
27 Correct 39 ms 9488 KB Output is correct
28 Correct 36 ms 9296 KB Output is correct
29 Correct 37 ms 9432 KB Output is correct
30 Correct 35 ms 9316 KB Output is correct
31 Correct 47 ms 9040 KB Output is correct
32 Correct 67 ms 8528 KB Output is correct
33 Correct 71 ms 8528 KB Output is correct
34 Correct 185 ms 18152 KB Output is correct
35 Correct 129 ms 23124 KB Output is correct
36 Correct 102 ms 23124 KB Output is correct
37 Correct 102 ms 23452 KB Output is correct
38 Correct 101 ms 23376 KB Output is correct
39 Correct 840 ms 63304 KB Output is correct
40 Execution timed out 2029 ms 178076 KB Time limit exceeded
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 2 ms 604 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 440 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 436 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 436 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 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 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 2 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 84 ms 8740 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 5900 KB Output is correct
37 Correct 22 ms 5596 KB Output is correct
38 Correct 58 ms 8272 KB Output is correct
39 Correct 38 ms 9300 KB Output is correct
40 Correct 71 ms 8528 KB Output is correct
41 Correct 80 ms 8532 KB Output is correct
42 Correct 40 ms 9296 KB Output is correct
43 Correct 41 ms 9552 KB Output is correct
44 Correct 36 ms 9300 KB Output is correct
45 Correct 15 ms 7128 KB Output is correct
46 Correct 28 ms 7132 KB Output is correct
47 Correct 36 ms 7732 KB Output is correct
48 Correct 46 ms 8528 KB Output is correct
49 Correct 46 ms 9040 KB Output is correct
50 Correct 45 ms 8788 KB Output is correct
51 Correct 45 ms 8784 KB Output is correct
52 Correct 68 ms 8532 KB Output is correct
53 Correct 70 ms 8532 KB Output is correct
54 Correct 75 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 2 ms 604 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 440 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 436 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 436 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 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 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 2 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 84 ms 8740 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 5900 KB Output is correct
37 Correct 22 ms 5596 KB Output is correct
38 Correct 58 ms 8272 KB Output is correct
39 Correct 38 ms 9300 KB Output is correct
40 Correct 71 ms 8528 KB Output is correct
41 Correct 80 ms 8532 KB Output is correct
42 Correct 40 ms 9296 KB Output is correct
43 Correct 41 ms 9552 KB Output is correct
44 Correct 36 ms 9300 KB Output is correct
45 Correct 15 ms 7128 KB Output is correct
46 Correct 28 ms 7132 KB Output is correct
47 Correct 36 ms 7732 KB Output is correct
48 Correct 46 ms 8528 KB Output is correct
49 Correct 46 ms 9040 KB Output is correct
50 Correct 45 ms 8788 KB Output is correct
51 Correct 45 ms 8784 KB Output is correct
52 Correct 68 ms 8532 KB Output is correct
53 Correct 70 ms 8532 KB Output is correct
54 Correct 75 ms 8536 KB Output is correct
55 Correct 220 ms 21652 KB Output is correct
56 Correct 39 ms 7988 KB Output is correct
57 Correct 186 ms 18236 KB Output is correct
58 Correct 181 ms 19416 KB Output is correct
59 Correct 131 ms 23052 KB Output is correct
60 Correct 194 ms 21600 KB Output is correct
61 Correct 225 ms 21644 KB Output is correct
62 Correct 110 ms 23252 KB Output is correct
63 Correct 103 ms 23380 KB Output is correct
64 Correct 100 ms 23360 KB Output is correct
65 Correct 45 ms 16956 KB Output is correct
66 Correct 72 ms 16820 KB Output is correct
67 Correct 99 ms 18956 KB Output is correct
68 Correct 121 ms 21120 KB Output is correct
69 Correct 154 ms 21652 KB Output is correct
70 Correct 122 ms 21584 KB Output is correct
71 Correct 128 ms 21332 KB Output is correct
72 Correct 180 ms 21584 KB Output is correct
73 Correct 189 ms 21700 KB Output is correct
74 Correct 204 ms 21588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 432 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 600 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 432 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 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 81 ms 8664 KB Output is correct
20 Correct 23 ms 5596 KB Output is correct
21 Correct 46 ms 9288 KB Output is correct
22 Correct 70 ms 8528 KB Output is correct
23 Correct 85 ms 8652 KB Output is correct
24 Correct 15 ms 7128 KB Output is correct
25 Correct 28 ms 6908 KB Output is correct
26 Correct 69 ms 8592 KB Output is correct
27 Correct 70 ms 8532 KB Output is correct
28 Correct 73 ms 8504 KB Output is correct
29 Correct 226 ms 21728 KB Output is correct
30 Correct 38 ms 7984 KB Output is correct
31 Correct 107 ms 23120 KB Output is correct
32 Correct 205 ms 21668 KB Output is correct
33 Correct 224 ms 21560 KB Output is correct
34 Correct 40 ms 16976 KB Output is correct
35 Correct 73 ms 16952 KB Output is correct
36 Correct 181 ms 21532 KB Output is correct
37 Correct 189 ms 21492 KB Output is correct
38 Correct 201 ms 21604 KB Output is correct
39 Execution timed out 2060 ms 169836 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 432 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 600 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 432 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 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 81 ms 8664 KB Output is correct
20 Correct 23 ms 5596 KB Output is correct
21 Correct 46 ms 9288 KB Output is correct
22 Correct 70 ms 8528 KB Output is correct
23 Correct 85 ms 8652 KB Output is correct
24 Correct 15 ms 7128 KB Output is correct
25 Correct 28 ms 6908 KB Output is correct
26 Correct 69 ms 8592 KB Output is correct
27 Correct 70 ms 8532 KB Output is correct
28 Correct 73 ms 8504 KB Output is correct
29 Correct 226 ms 21728 KB Output is correct
30 Correct 38 ms 7984 KB Output is correct
31 Correct 107 ms 23120 KB Output is correct
32 Correct 205 ms 21668 KB Output is correct
33 Correct 224 ms 21560 KB Output is correct
34 Correct 40 ms 16976 KB Output is correct
35 Correct 73 ms 16952 KB Output is correct
36 Correct 181 ms 21532 KB Output is correct
37 Correct 189 ms 21492 KB Output is correct
38 Correct 201 ms 21604 KB Output is correct
39 Execution timed out 2060 ms 169836 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 432 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 600 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 432 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 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 81 ms 8664 KB Output is correct
20 Correct 23 ms 5596 KB Output is correct
21 Correct 46 ms 9288 KB Output is correct
22 Correct 70 ms 8528 KB Output is correct
23 Correct 85 ms 8652 KB Output is correct
24 Correct 15 ms 7128 KB Output is correct
25 Correct 28 ms 6908 KB Output is correct
26 Correct 69 ms 8592 KB Output is correct
27 Correct 70 ms 8532 KB Output is correct
28 Correct 73 ms 8504 KB Output is correct
29 Correct 226 ms 21728 KB Output is correct
30 Correct 38 ms 7984 KB Output is correct
31 Correct 107 ms 23120 KB Output is correct
32 Correct 205 ms 21668 KB Output is correct
33 Correct 224 ms 21560 KB Output is correct
34 Correct 40 ms 16976 KB Output is correct
35 Correct 73 ms 16952 KB Output is correct
36 Correct 181 ms 21532 KB Output is correct
37 Correct 189 ms 21492 KB Output is correct
38 Correct 201 ms 21604 KB Output is correct
39 Execution timed out 2060 ms 169836 KB Time limit exceeded
40 Halted 0 ms 0 KB -