답안 #888242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888242 2023-12-16T15:39:50 Z ace5 Maze (JOI23_ho_t3) C++17
35 / 100
787 ms 582132 KB
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;
const int maxr = 3001;
const int maxc = 6000001;

set<int> r[maxr];
set<short> c[maxc];
vector<short> vis[maxr];
vector<int> d[maxr];
vector<bool> a[maxr];
deque<pair<int,int>> f;

int R,C,n;

int bfs(int si,int sj,int fi,int fj)
{
    for(int i = 0;i < R;++i)
    {
        d[i].resize(C);
        vis[i].resize(C);
        for(int j = 0;j < C;++j)
        {
            d[i][j] = INF;
            vis[i][j] = 0;
            if(i != si || j != sj)
            {
                r[i].insert(j);
                c[j].insert(i);

            }
        }
    }
    d[si][sj] = 0;
    vis[si][sj] = 2;
    f.push_back({si,sj});
    while(f.size())
    {
        int i = f[0].first;
        int j = f[0].second;
        f.pop_front();
       // cout << i << ' ' << j << ' ' << d[fi][fj] << ' ' << vis[5][0] << "\n";
        if(vis[i][j] == 3)
            continue;
        vis[i][j] = 3;
        if(i == fi && j == fj)
            break;
        if(i > 0 && a[i-1][j] == 0 && vis[i-1][j] < 2)
        {
            if(!vis[i-1][j])
            {
                r[i-1].erase(j);
                c[j].erase(i-1);
            }
            vis[i-1][j] = 2;
            d[i-1][j] = d[i][j];
            f.push_front({i-1,j});
        }
        if(j > 0 && a[i][j-1] == 0 && vis[i][j-1] < 2)
        {
            if(!vis[i][j-1])
            {
                r[i].erase(j-1);
                c[j-1].erase(i);
            }
          //  if(i == 5 && j == 1)
         //   {
          //      cout << d[i][j] << ' ' << d[i][j-1] << "\n";
          //  }
            vis[i][j-1] = 2;
            d[i][j-1] = d[i][j];
            f.push_front({i,j-1});
        }
        if(i < R-1 && a[i+1][j] == 0 && vis[i+1][j] < 2)
        {
            if(!vis[i+1][j])
            {
                r[i+1].erase(j);
                c[j].erase(i+1);
            }
            vis[i+1][j] = 2;
            d[i+1][j] = d[i][j];
            f.push_front({i+1,j});
        }
        if(j < C-1 && a[i][j+1] == 0 && vis[i][j+1] < 2)
        {
            if(!vis[i][j+1])
            {
                r[i].erase(j+1);
                c[j+1].erase(i);
            }
            vis[i][j+1] = 2;
            d[i][j+1] = d[i][j];
            f.push_front({i,j+1});
        }
        if(abs(i-fi) <= n && abs(j-fj) <= n && !vis[fi][fj])
        {
            r[fi].erase(fj);
            c[fj].erase(fi);
            //cout << i << ' ' << j << ' ' << d[i][j] << "!\n";
            vis[fi][fj] = 1;
            d[fi][fj] = d[i][j]+1;
            f.push_back({fi,fj});
        }
        int indd = min(R-1,i+n);
        int indu = max(0,i-n);
        short indl = max(0,j-n);
        short indr = min(C-1,j+n);
        int indd2 = i+n-1;
        int indu2 = i-n+1;
        short indr2 = j+n-1;
        short indl2 = j-n+1;
        for(;;)
        {
            auto it = r[indd].lower_bound(indl2);
            if(it != r[indd].end() && (*it) <= indr2)
            {
                int k = (*it);
                vis[indd][k] = 1;
                //cout << indd << ' ' << k << ' ' << d[i][j] << "!\n";
                d[indd][k] = d[i][j]+1;
                //cout << d[1][0] << ' ';
                f.push_back({indd,k});
                r[indd].erase(it);
                c[(*it)].erase(indd);
            }
            else
                break;
        }
        for(;;)
        {
            auto it = r[indu].lower_bound(indl2);
            if(it != r[indu].end() && (*it) <= indr2)
            {
                int k = (*it);
                vis[indu][k] = 1;
                d[indu][k] = d[i][j]+1;
                //cout << indu << ' ' << k << "!!\n";
                f.push_back({indu,k});
                r[indu].erase(it);
                c[(*it)].erase(indu);
            }
            else
                break;
        }
        for(;;)
        {
            auto it = c[indl].lower_bound(indu2);
            if(it != c[indl].end() && (*it) <= indd2)
            {
                int k = (*it);
                vis[k][indl] = 1;
                d[k][indl] = d[i][j]+1;
                //cout << k << ' ' << indl << "!!!\n";
                f.push_back({k,indl});
                c[indl].erase(it);
                r[(*it)].erase(indl);
            }
            else
                break;
        }
        for(;;)
        {
            auto it = c[indr].lower_bound(indu2);
            if(it != c[indr].end() && (*it) <= indd2)
            {
                int k = (*it);
                vis[k][indr] = 1;
                d[k][indr] = d[i][j]+1;
                //cout << k << ' ' << indr << "!!!!\n";
                f.push_back({k,indr});
                c[indr].erase(it);
                r[(*it)].erase(indr);
            }
            else
                break;
        }
    }
    return d[fi][fj];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> R >> C >> n;
    int si,sj,fi,fj;
    cin >> si >> sj >> fi >> fj;
    si--;
    sj--;
    fi--;
    fj--;
    for(int i = 0;i < R;++i)
    {
        string s;
        cin >> s;
        a[i].resize(C);
        for(int j =0;j < C;++j)
        {
            a[i][j] = (s[j] == '.' ? 0 : 1);
        }
    }
    cout << bfs(si,sj,fi,fj) << "\n";
    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 282436 KB Output is correct
2 Correct 54 ms 282636 KB Output is correct
3 Correct 61 ms 282704 KB Output is correct
4 Correct 55 ms 282668 KB Output is correct
5 Correct 56 ms 282496 KB Output is correct
6 Correct 55 ms 282692 KB Output is correct
7 Correct 54 ms 282732 KB Output is correct
8 Correct 61 ms 282708 KB Output is correct
9 Correct 54 ms 282628 KB Output is correct
10 Correct 57 ms 282452 KB Output is correct
11 Correct 55 ms 282452 KB Output is correct
12 Correct 55 ms 282452 KB Output is correct
13 Correct 53 ms 282448 KB Output is correct
14 Correct 60 ms 282596 KB Output is correct
15 Correct 55 ms 282636 KB Output is correct
16 Correct 54 ms 282724 KB Output is correct
17 Correct 54 ms 282704 KB Output is correct
18 Correct 54 ms 282704 KB Output is correct
19 Correct 75 ms 288508 KB Output is correct
20 Runtime error 291 ms 582132 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 282460 KB Output is correct
2 Correct 54 ms 282448 KB Output is correct
3 Correct 54 ms 282632 KB Output is correct
4 Correct 56 ms 282456 KB Output is correct
5 Correct 54 ms 282700 KB Output is correct
6 Correct 55 ms 282400 KB Output is correct
7 Correct 59 ms 282792 KB Output is correct
8 Correct 55 ms 282452 KB Output is correct
9 Correct 54 ms 282600 KB Output is correct
10 Correct 55 ms 282704 KB Output is correct
11 Correct 55 ms 282716 KB Output is correct
12 Correct 55 ms 282704 KB Output is correct
13 Correct 53 ms 282704 KB Output is correct
14 Correct 54 ms 282556 KB Output is correct
15 Correct 54 ms 282708 KB Output is correct
16 Correct 54 ms 282716 KB Output is correct
17 Correct 55 ms 282548 KB Output is correct
18 Correct 55 ms 282452 KB Output is correct
19 Correct 56 ms 282708 KB Output is correct
20 Correct 53 ms 282908 KB Output is correct
21 Correct 54 ms 282452 KB Output is correct
22 Correct 55 ms 282452 KB Output is correct
23 Correct 57 ms 282656 KB Output is correct
24 Correct 54 ms 282444 KB Output is correct
25 Correct 54 ms 282444 KB Output is correct
26 Correct 54 ms 282452 KB Output is correct
27 Correct 54 ms 282488 KB Output is correct
28 Correct 54 ms 282688 KB Output is correct
29 Correct 54 ms 282428 KB Output is correct
30 Correct 54 ms 282712 KB Output is correct
31 Correct 54 ms 282576 KB Output is correct
32 Correct 54 ms 282704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 282448 KB Output is correct
2 Correct 54 ms 282452 KB Output is correct
3 Correct 53 ms 282456 KB Output is correct
4 Correct 54 ms 282448 KB Output is correct
5 Correct 58 ms 282628 KB Output is correct
6 Correct 60 ms 282448 KB Output is correct
7 Correct 54 ms 282708 KB Output is correct
8 Correct 54 ms 282704 KB Output is correct
9 Correct 55 ms 282704 KB Output is correct
10 Correct 55 ms 282708 KB Output is correct
11 Correct 55 ms 282960 KB Output is correct
12 Correct 54 ms 282708 KB Output is correct
13 Correct 53 ms 282460 KB Output is correct
14 Correct 58 ms 282704 KB Output is correct
15 Correct 54 ms 282560 KB Output is correct
16 Correct 55 ms 282456 KB Output is correct
17 Correct 56 ms 282540 KB Output is correct
18 Correct 54 ms 282444 KB Output is correct
19 Correct 58 ms 282448 KB Output is correct
20 Correct 54 ms 282460 KB Output is correct
21 Correct 54 ms 282704 KB Output is correct
22 Correct 54 ms 282964 KB Output is correct
23 Correct 54 ms 282708 KB Output is correct
24 Correct 54 ms 282668 KB Output is correct
25 Correct 64 ms 286288 KB Output is correct
26 Correct 68 ms 287824 KB Output is correct
27 Correct 73 ms 288644 KB Output is correct
28 Correct 73 ms 288596 KB Output is correct
29 Correct 71 ms 288596 KB Output is correct
30 Correct 71 ms 288592 KB Output is correct
31 Correct 71 ms 288592 KB Output is correct
32 Correct 72 ms 288552 KB Output is correct
33 Correct 72 ms 288624 KB Output is correct
34 Correct 91 ms 294488 KB Output is correct
35 Correct 97 ms 297552 KB Output is correct
36 Correct 103 ms 297556 KB Output is correct
37 Correct 100 ms 297568 KB Output is correct
38 Correct 101 ms 297888 KB Output is correct
39 Correct 215 ms 326144 KB Output is correct
40 Correct 628 ms 409420 KB Output is correct
41 Correct 663 ms 432824 KB Output is correct
42 Correct 625 ms 432468 KB Output is correct
43 Correct 557 ms 432584 KB Output is correct
44 Correct 559 ms 432536 KB Output is correct
45 Correct 787 ms 432548 KB Output is correct
46 Correct 763 ms 432876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 282460 KB Output is correct
2 Correct 54 ms 282448 KB Output is correct
3 Correct 54 ms 282632 KB Output is correct
4 Correct 56 ms 282456 KB Output is correct
5 Correct 54 ms 282700 KB Output is correct
6 Correct 55 ms 282400 KB Output is correct
7 Correct 59 ms 282792 KB Output is correct
8 Correct 55 ms 282452 KB Output is correct
9 Correct 54 ms 282600 KB Output is correct
10 Correct 55 ms 282704 KB Output is correct
11 Correct 55 ms 282716 KB Output is correct
12 Correct 55 ms 282704 KB Output is correct
13 Correct 53 ms 282704 KB Output is correct
14 Correct 54 ms 282556 KB Output is correct
15 Correct 54 ms 282708 KB Output is correct
16 Correct 54 ms 282716 KB Output is correct
17 Correct 55 ms 282548 KB Output is correct
18 Correct 55 ms 282452 KB Output is correct
19 Correct 56 ms 282708 KB Output is correct
20 Correct 53 ms 282908 KB Output is correct
21 Correct 54 ms 282452 KB Output is correct
22 Correct 55 ms 282452 KB Output is correct
23 Correct 57 ms 282656 KB Output is correct
24 Correct 54 ms 282444 KB Output is correct
25 Correct 54 ms 282444 KB Output is correct
26 Correct 54 ms 282452 KB Output is correct
27 Correct 54 ms 282488 KB Output is correct
28 Correct 54 ms 282688 KB Output is correct
29 Correct 54 ms 282428 KB Output is correct
30 Correct 54 ms 282712 KB Output is correct
31 Correct 54 ms 282576 KB Output is correct
32 Correct 54 ms 282704 KB Output is correct
33 Correct 75 ms 288492 KB Output is correct
34 Correct 55 ms 282808 KB Output is correct
35 Correct 55 ms 282964 KB Output is correct
36 Correct 65 ms 286292 KB Output is correct
37 Runtime error 275 ms 582012 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 282460 KB Output is correct
2 Correct 54 ms 282448 KB Output is correct
3 Correct 54 ms 282632 KB Output is correct
4 Correct 56 ms 282456 KB Output is correct
5 Correct 54 ms 282700 KB Output is correct
6 Correct 55 ms 282400 KB Output is correct
7 Correct 59 ms 282792 KB Output is correct
8 Correct 55 ms 282452 KB Output is correct
9 Correct 54 ms 282600 KB Output is correct
10 Correct 55 ms 282704 KB Output is correct
11 Correct 55 ms 282716 KB Output is correct
12 Correct 55 ms 282704 KB Output is correct
13 Correct 53 ms 282704 KB Output is correct
14 Correct 54 ms 282556 KB Output is correct
15 Correct 54 ms 282708 KB Output is correct
16 Correct 54 ms 282716 KB Output is correct
17 Correct 55 ms 282548 KB Output is correct
18 Correct 55 ms 282452 KB Output is correct
19 Correct 56 ms 282708 KB Output is correct
20 Correct 53 ms 282908 KB Output is correct
21 Correct 54 ms 282452 KB Output is correct
22 Correct 55 ms 282452 KB Output is correct
23 Correct 57 ms 282656 KB Output is correct
24 Correct 54 ms 282444 KB Output is correct
25 Correct 54 ms 282444 KB Output is correct
26 Correct 54 ms 282452 KB Output is correct
27 Correct 54 ms 282488 KB Output is correct
28 Correct 54 ms 282688 KB Output is correct
29 Correct 54 ms 282428 KB Output is correct
30 Correct 54 ms 282712 KB Output is correct
31 Correct 54 ms 282576 KB Output is correct
32 Correct 54 ms 282704 KB Output is correct
33 Correct 75 ms 288492 KB Output is correct
34 Correct 55 ms 282808 KB Output is correct
35 Correct 55 ms 282964 KB Output is correct
36 Correct 65 ms 286292 KB Output is correct
37 Runtime error 275 ms 582012 KB Execution killed with signal 11
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 282436 KB Output is correct
2 Correct 54 ms 282636 KB Output is correct
3 Correct 61 ms 282704 KB Output is correct
4 Correct 55 ms 282668 KB Output is correct
5 Correct 56 ms 282496 KB Output is correct
6 Correct 55 ms 282692 KB Output is correct
7 Correct 54 ms 282732 KB Output is correct
8 Correct 61 ms 282708 KB Output is correct
9 Correct 54 ms 282628 KB Output is correct
10 Correct 57 ms 282452 KB Output is correct
11 Correct 55 ms 282452 KB Output is correct
12 Correct 55 ms 282452 KB Output is correct
13 Correct 53 ms 282448 KB Output is correct
14 Correct 60 ms 282596 KB Output is correct
15 Correct 55 ms 282636 KB Output is correct
16 Correct 54 ms 282724 KB Output is correct
17 Correct 54 ms 282704 KB Output is correct
18 Correct 54 ms 282704 KB Output is correct
19 Correct 75 ms 288508 KB Output is correct
20 Runtime error 291 ms 582132 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 282436 KB Output is correct
2 Correct 54 ms 282636 KB Output is correct
3 Correct 61 ms 282704 KB Output is correct
4 Correct 55 ms 282668 KB Output is correct
5 Correct 56 ms 282496 KB Output is correct
6 Correct 55 ms 282692 KB Output is correct
7 Correct 54 ms 282732 KB Output is correct
8 Correct 61 ms 282708 KB Output is correct
9 Correct 54 ms 282628 KB Output is correct
10 Correct 57 ms 282452 KB Output is correct
11 Correct 55 ms 282452 KB Output is correct
12 Correct 55 ms 282452 KB Output is correct
13 Correct 53 ms 282448 KB Output is correct
14 Correct 60 ms 282596 KB Output is correct
15 Correct 55 ms 282636 KB Output is correct
16 Correct 54 ms 282724 KB Output is correct
17 Correct 54 ms 282704 KB Output is correct
18 Correct 54 ms 282704 KB Output is correct
19 Correct 75 ms 288508 KB Output is correct
20 Runtime error 291 ms 582132 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 282436 KB Output is correct
2 Correct 54 ms 282636 KB Output is correct
3 Correct 61 ms 282704 KB Output is correct
4 Correct 55 ms 282668 KB Output is correct
5 Correct 56 ms 282496 KB Output is correct
6 Correct 55 ms 282692 KB Output is correct
7 Correct 54 ms 282732 KB Output is correct
8 Correct 61 ms 282708 KB Output is correct
9 Correct 54 ms 282628 KB Output is correct
10 Correct 57 ms 282452 KB Output is correct
11 Correct 55 ms 282452 KB Output is correct
12 Correct 55 ms 282452 KB Output is correct
13 Correct 53 ms 282448 KB Output is correct
14 Correct 60 ms 282596 KB Output is correct
15 Correct 55 ms 282636 KB Output is correct
16 Correct 54 ms 282724 KB Output is correct
17 Correct 54 ms 282704 KB Output is correct
18 Correct 54 ms 282704 KB Output is correct
19 Correct 75 ms 288508 KB Output is correct
20 Runtime error 291 ms 582132 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -