답안 #1025164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025164 2024-07-16T16:55:44 Z Dennis_Jason Awesome Arrowland Adventure (eJOI19_adventure) C++14
50 / 100
48 ms 46992 KB
#include <bits/stdc++.h>
#define NMAX 200001
#define int long long
#define MAX 1001
#define pb push_back
#define eb emplace_back
#define MOD 1000000007
#define nl '\n'
#define INF  1000000007
#define LLONG_MAX 9223372036854775807
#define pii pair<int,int>
#define tpl tuple<int,int,int,int>
#pragma GCC optimize("O3")
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
int n,m;
int mat[501][501];
bool vis[501][501];
int dp[501][501];
bool inmat(int i,int j)
{
    return i>=1 && i<=n && j>=1 && j<=m;
}
vector<vector<pii>>G(NMAX);
int ind;
vector<int>dist(NMAX);
int calc_pos(int i,int j)
{
    return (i-1)*m+j;
}
void dijkstra(int node)
{
    priority_queue<pii,vector<pii>,greater<pii>>pq;
    pq.push({0,node});
    dist[node]=0;
    while(!pq.empty())
    {
        auto [rot,first]=pq.top();
        pq.pop();
        for(auto [x,w]:G[first])
        {
            if(dist[x]>dist[first]+w)
            {
                dist[x]=dist[first]+w;
                pq.push({dist[x],x});
            }
        }
    }
}
signed main()
{
    cin>>n>>m;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            char x;
            cin>>x;
            if(x=='N')
                mat[i][j]=1;
            else if(x=='E')
                mat[i][j]=2;
            else if(x=='S')
                mat[i][j]=3;
            else if(x=='W')
                mat[i][j]=4;
            else
                mat[i][j]=5;
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            dist[calc_pos(i,j)]=INF;
            if(mat[i][j]==1)
            {
                if(inmat(i-1,j))
                    G[calc_pos(i,j)].pb({calc_pos(i-1,j),0});
                if(inmat(i,j+1))
                    G[calc_pos(i,j)].pb({calc_pos(i,j+1),1});
                if(inmat(i+1,j))
                    G[calc_pos(i,j)].pb({calc_pos(i+1,j),2});
                if(inmat(i,j-1))
                    G[calc_pos(i,j)].pb({calc_pos(i,j-1),3});
            }
            else if(mat[i][j]==2)
            {
                if(inmat(i,j+1))
                    G[calc_pos(i,j)].pb({calc_pos(i,j+1),0});
                if(inmat(i+1,j))
                    G[calc_pos(i,j)].pb({calc_pos(i+1,j),1});
                if(inmat(i,j-1))
                    G[calc_pos(i,j)].pb({calc_pos(i,j-1),2});
                if(inmat(i-1,j))
                    G[calc_pos(i,j)].pb({calc_pos(i-1,j),3});
            }
            else if(mat[i][j]==3)
            {
                if(inmat(i+1,j))
                    G[calc_pos(i,j)].pb({calc_pos(i+1,j),0});
                if(inmat(i,j-1))
                    G[calc_pos(i,j)].pb({calc_pos(i,j-1),1});
                if(inmat(i-1,j))
                    G[calc_pos(i,j)].pb({calc_pos(i-1,j),2});
                if(inmat(i,j+1))
                    G[calc_pos(i,j)].pb({calc_pos(i,j+1),3});
            }
            else if(mat[i][j]==4)
            {
                if(inmat(i,j-1))
                    G[calc_pos(i,j)].pb({calc_pos(i,j-1),0});
                if(inmat(i-1,j))
                    G[calc_pos(i,j)].pb({calc_pos(i-1,j),1});
                if(inmat(i,j+1))
                    G[calc_pos(i,j)].pb({calc_pos(i,j+1),2});
                if(inmat(i+1,j))
                    G[calc_pos(i,j)].pb({calc_pos(i+1,j),3});
            }
        }
    }
    if(mat[1][1]==5)
    {
        cout<<-1;
        return 0;
    }
    dijkstra(1);
    if(dist[calc_pos(n,m)]==INF)
        cout<<-1;
    else
        cout<<dist[calc_pos(n,m)];



    return 0;
}

Compilation message

adventure.cpp:10: warning: "LLONG_MAX" redefined
   10 | #define LLONG_MAX 9223372036854775807
      | 
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
                 from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from adventure.cpp:1:
/usr/include/limits.h:135: note: this is the location of the previous definition
  135 | #  define LLONG_MAX __LONG_LONG_MAX__
      | 
adventure.cpp: In function 'void dijkstra(long long int)':
adventure.cpp:39:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |         auto [rot,first]=pq.top();
      |              ^
adventure.cpp:41:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |         for(auto [x,w]:G[first])
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8796 KB Output is correct
2 Correct 2 ms 8680 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8776 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 3 ms 8776 KB Output is correct
9 Correct 2 ms 8576 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8796 KB Output is correct
2 Correct 2 ms 8680 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8776 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 3 ms 8776 KB Output is correct
9 Correct 2 ms 8576 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8544 KB Output is correct
15 Correct 3 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 4 ms 8536 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8768 KB Output is correct
2 Correct 2 ms 8776 KB Output is correct
3 Correct 3 ms 8796 KB Output is correct
4 Correct 3 ms 8780 KB Output is correct
5 Correct 3 ms 8796 KB Output is correct
6 Correct 3 ms 8796 KB Output is correct
7 Correct 3 ms 8796 KB Output is correct
8 Correct 4 ms 8568 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8796 KB Output is correct
2 Correct 2 ms 8680 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 3 ms 8796 KB Output is correct
5 Correct 3 ms 8776 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 3 ms 8776 KB Output is correct
9 Correct 2 ms 8576 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8544 KB Output is correct
15 Correct 3 ms 8792 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 4 ms 8536 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8540 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8540 KB Output is correct
25 Correct 3 ms 8768 KB Output is correct
26 Correct 2 ms 8776 KB Output is correct
27 Correct 3 ms 8796 KB Output is correct
28 Correct 3 ms 8780 KB Output is correct
29 Correct 3 ms 8796 KB Output is correct
30 Correct 3 ms 8796 KB Output is correct
31 Correct 3 ms 8796 KB Output is correct
32 Correct 4 ms 8568 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 3 ms 8540 KB Output is correct
35 Correct 10 ms 10332 KB Output is correct
36 Correct 4 ms 8796 KB Output is correct
37 Correct 14 ms 10892 KB Output is correct
38 Correct 14 ms 12380 KB Output is correct
39 Runtime error 48 ms 46992 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -