답안 #418391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418391 2021-06-05T10:36:26 Z DJeniUp 포탈들 (BOI14_portals) C++17
100 / 100
857 ms 162444 KB
#include <bits/stdc++.h>

using namespace std;

typedef int ll;
typedef pair<ll,ll>pairll;
typedef pair<ll,pairll>pairlll;
typedef pair<pairll,ll>pairllL;
typedef pair<pairll,pairll>pairllll;
typedef pair<ll,pairllll>pairlllll;
typedef long double ld;
typedef pair<ll,string>pairls;

#define endl '\n'
#define INF 100000000007
#define M 1000000000
#define P 316
#define MOD 998244353
#define pb push_back
#define fr first
#define sc second

ll n,m,d[1007][1007],a,b,t[1007][1007],f[1007][1007];
ll up[1007][1007],down[1007][1007],Left[1007][1007],Right[1007][1007];

char c;

vector<pairllL>v[1007][1007];

priority_queue<pairlll, vector<pairlll>, greater<pairlll> >q;

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>c;
            if(c=='.')d[i][j]=0;
            else if(c=='#')d[i][j]=1;
            else if(c=='C')d[i][j]=2;
            else if(c=='S')d[i][j]=3;
            t[i][j]=INF;
        }
    }
    for(int i=1;i<=n;i++){
        d[i][0]=1;
        d[i][m+1]=1;
    }
    for(int i=1;i<=m;i++){
        d[0][i]=1;
        d[n+1][i]=1;
    }
    ////////1
    for(int i=1;i<=n;i++){
        a=-1;
        for(int j=1;j<=m;j++){
            if(d[i][j]!=1){
                a++;
                Left[i][j]=a;
            }else{
                a=-1;
            }
        }
    }
    ////////2
    for(int i=1;i<=n;i++){
        a=-1;
        for(int j=m;j>=1;j--){
            if(d[i][j]!=1){
                a++;
                Right[i][j]=a;
            }else{
                a=-1;
                b=-1;
            }
        }
    }
    ////////3
    for(int j=1;j<=m;j++){
        a=-1;
        for(int i=1;i<=n;i++){
            if(d[i][j]!=1){
                a++;
                up[i][j]=a;
            }else{
                a=-1;
                b=-1;
            }
        }
    }
    ////////4
    for(int j=1;j<=m;j++){
        a=-1;
        for(int i=n;i>=1;i--){
            if(d[i][j]!=1){
                a++;
                down[i][j]=a;
            }else{
                a=-1;
                b=-1;
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(d[i][j]!=1){
                if(d[i+1][j]!=1){
                    v[i][j].pb({{i+1,j},1});
                }
                if(d[i-1][j]!=1){
                    v[i][j].pb({{i-1,j},1});
                }
                if(d[i][j+1]!=1){
                    v[i][j].pb({{i,j+1},1});
                }
                if(d[i][j-1]!=1){
                    v[i][j].pb({{i,j-1},1});
                }
                b=min(min(up[i][j],down[i][j]),min(Left[i][j],Right[i][j]));
                if(up[i][j]!=0)v[i][j].pb({{i-up[i][j],j},b+1});
                if(down[i][j]!=0)v[i][j].pb({{i+down[i][j],j},b+1});
                if(Left[i][j]!=0)v[i][j].pb({{i,j-Left[i][j]},b+1});
                if(Right[i][j]!=0)v[i][j].pb({{i,j+Right[i][j]},b+1});
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(d[i][j]==3){
                q.push({0,{i,j}});
                break;
            }
        }
    }
    while(q.size()>0){
        ll m1=q.top().fr;
        ll m2=q.top().sc.fr;
        ll m3=q.top().sc.sc;
        q.pop();
        if(f[m2][m3]==0){
            f[m2][m3]=1;
            t[m2][m3]=m1;
            for(int i=0;i<v[m2][m3].size();i++){
                a=v[m2][m3][i].fr.fr;
                b=v[m2][m3][i].fr.sc;
                ll h=v[m2][m3][i].sc;
                if(f[a][b]==0 && t[a][b]>m1+h){
                    t[a][b]=m1+h;
                    q.push({m1+h,{a,b}});
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(d[i][j]==2){
                cout<<t[i][j]<<endl;
                return 0;
            }
        }
    }
    cout<<0<<endl;

    return 0;
}

Compilation message

portals.cpp: In function 'int main()':
portals.cpp:15:13: warning: overflow in conversion from 'long int' to 'll' {aka 'int'} changes value from '100000000007' to '1215752199' [-Woverflow]
   15 | #define INF 100000000007
      |             ^~~~~~~~~~~~
portals.cpp:42:21: note: in expansion of macro 'INF'
   42 |             t[i][j]=INF;
      |                     ^~~
portals.cpp:143:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |             for(int i=0;i<v[m2][m3].size();i++){
      |                         ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 24140 KB Output is correct
2 Correct 15 ms 24396 KB Output is correct
3 Correct 17 ms 24380 KB Output is correct
4 Correct 16 ms 24288 KB Output is correct
5 Correct 17 ms 24380 KB Output is correct
6 Correct 18 ms 24396 KB Output is correct
7 Correct 17 ms 24392 KB Output is correct
8 Correct 16 ms 24396 KB Output is correct
9 Correct 16 ms 24288 KB Output is correct
10 Correct 16 ms 24232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 24120 KB Output is correct
2 Correct 16 ms 24352 KB Output is correct
3 Correct 16 ms 24428 KB Output is correct
4 Correct 16 ms 24208 KB Output is correct
5 Correct 16 ms 24332 KB Output is correct
6 Correct 16 ms 24396 KB Output is correct
7 Correct 16 ms 24348 KB Output is correct
8 Correct 16 ms 24432 KB Output is correct
9 Correct 18 ms 25696 KB Output is correct
10 Correct 18 ms 25792 KB Output is correct
11 Correct 18 ms 25560 KB Output is correct
12 Correct 17 ms 25548 KB Output is correct
13 Correct 18 ms 25548 KB Output is correct
14 Correct 16 ms 24268 KB Output is correct
15 Correct 17 ms 25628 KB Output is correct
16 Correct 16 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 24176 KB Output is correct
2 Correct 16 ms 24400 KB Output is correct
3 Correct 16 ms 24424 KB Output is correct
4 Correct 16 ms 24396 KB Output is correct
5 Correct 31 ms 31040 KB Output is correct
6 Correct 32 ms 31364 KB Output is correct
7 Correct 34 ms 31684 KB Output is correct
8 Correct 27 ms 31288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 24140 KB Output is correct
2 Correct 16 ms 24296 KB Output is correct
3 Correct 16 ms 24396 KB Output is correct
4 Correct 18 ms 24268 KB Output is correct
5 Correct 16 ms 24324 KB Output is correct
6 Correct 15 ms 24376 KB Output is correct
7 Correct 17 ms 24396 KB Output is correct
8 Correct 16 ms 24428 KB Output is correct
9 Correct 19 ms 25712 KB Output is correct
10 Correct 18 ms 25700 KB Output is correct
11 Correct 18 ms 25576 KB Output is correct
12 Correct 17 ms 25548 KB Output is correct
13 Correct 18 ms 25672 KB Output is correct
14 Correct 30 ms 31100 KB Output is correct
15 Correct 32 ms 31280 KB Output is correct
16 Correct 34 ms 31800 KB Output is correct
17 Correct 33 ms 31888 KB Output is correct
18 Correct 41 ms 32800 KB Output is correct
19 Correct 44 ms 33988 KB Output is correct
20 Correct 41 ms 34044 KB Output is correct
21 Correct 30 ms 31128 KB Output is correct
22 Correct 32 ms 31116 KB Output is correct
23 Correct 33 ms 31356 KB Output is correct
24 Correct 40 ms 34008 KB Output is correct
25 Correct 16 ms 24268 KB Output is correct
26 Correct 18 ms 25676 KB Output is correct
27 Correct 16 ms 24240 KB Output is correct
28 Correct 27 ms 31272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 24176 KB Output is correct
2 Correct 16 ms 24396 KB Output is correct
3 Correct 16 ms 24320 KB Output is correct
4 Correct 16 ms 24268 KB Output is correct
5 Correct 17 ms 24396 KB Output is correct
6 Correct 16 ms 24344 KB Output is correct
7 Correct 17 ms 24396 KB Output is correct
8 Correct 16 ms 24316 KB Output is correct
9 Correct 18 ms 25796 KB Output is correct
10 Correct 19 ms 25676 KB Output is correct
11 Correct 18 ms 25620 KB Output is correct
12 Correct 18 ms 25548 KB Output is correct
13 Correct 18 ms 25676 KB Output is correct
14 Correct 31 ms 31156 KB Output is correct
15 Correct 33 ms 31344 KB Output is correct
16 Correct 37 ms 31792 KB Output is correct
17 Correct 36 ms 31932 KB Output is correct
18 Correct 37 ms 32648 KB Output is correct
19 Correct 43 ms 33964 KB Output is correct
20 Correct 40 ms 34024 KB Output is correct
21 Correct 30 ms 31168 KB Output is correct
22 Correct 30 ms 31192 KB Output is correct
23 Correct 33 ms 31440 KB Output is correct
24 Correct 489 ms 119672 KB Output is correct
25 Correct 857 ms 162444 KB Output is correct
26 Correct 709 ms 162372 KB Output is correct
27 Correct 697 ms 162272 KB Output is correct
28 Correct 364 ms 90008 KB Output is correct
29 Correct 391 ms 90692 KB Output is correct
30 Correct 449 ms 93252 KB Output is correct
31 Correct 41 ms 33992 KB Output is correct
32 Correct 693 ms 162168 KB Output is correct
33 Correct 15 ms 24268 KB Output is correct
34 Correct 17 ms 25652 KB Output is correct
35 Correct 509 ms 123200 KB Output is correct
36 Correct 16 ms 24140 KB Output is correct
37 Correct 26 ms 31336 KB Output is correct
38 Correct 301 ms 94496 KB Output is correct
39 Correct 308 ms 83960 KB Output is correct