Submission #730601

# Submission time Handle Problem Language Result Execution time Memory
730601 2023-04-26T07:36:05 Z AtabayRajabli Awesome Arrowland Adventure (eJOI19_adventure) C++11
0 / 100
1 ms 1268 KB
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MAX 5e4 + 1
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 0x3F3F3F3F
#define INFLL 0x3F3F3F3F3F3F3F3FLL
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sec second
#define fi first
 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
 
int d[501][501], g[501][501], n, m;
 
int v[4] = {1, 0, 0, -1};
int f[4] = {0, -1, 1, 0};
 
void dijkstra(int x, int y)
{
    d[x][y] = 0;
    
    priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> q;
    q.push({0, {x, y}});
    
    while(!q.empty())
    {
        int a, b, w;
        a = q.top().sec.fi;
        b = q.top().sec.sec;
        w = q.top().fi;
        q.pop();
        
        for(int i = 0; i<4; i++)
        {
            int xx = a + v[i], yy = b + f[i];
            
            if(xx >=0 && xx<=n && yy>=0 && yy<=m)
            {
                if(d[a][b] + abs(w - g[xx][yy]) < d[xx][yy])
                {
                    d[xx][yy] = d[a][b] + abs(w - g[xx][yy]);
                    q.push({d[xx][yy], {xx, yy}});
                }
            }
        }
    }
}
 
void $()
{
    cin >> n >> m;
    
    for(int i = 0; i<501; i++)
    {
        for(int j = 0; j<501; j++)
        {
            d[i][j] = INF;
        }
    }
    
    for(int i = 1 ; i<=n; i++)
    {
        for(int j = 1; j<=m; j++)
        {
            char c;
            int k;
            cin >> c;
            
            if(c == 'N')k = 1;
            if(c == 'E')k = 2;
            if(c == 'S')k = 3;
            if(c == 'W')k = 4;
            
            g[i][j] = k;
        }
    }
    
    dijkstra(1, 1);
    
    cout << d[n][m];
}
 
int main()
{
    OPT
 
    int t = 1;
 
    while(t--)
        $();
}

Compilation message

adventure.cpp: In function 'void $()':
adventure.cpp:79:21: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
   79 |             g[i][j] = k;
      |             ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -