Submission #1020811

# Submission time Handle Problem Language Result Execution time Memory
1020811 2024-07-12T10:12:33 Z adrielcp Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
76 ms 9376 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld double
#define int ll
#define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout);
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// const ll INF = 1e18;
const int INF = 1e18;
const int mod = 1e9+7;
const lld PI = acos(-1.0);
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};
#define debug(x) cout << #x << ": " << x << endl;
#define add(a, b) a += b, a %= mod
#define mul(a, b) ((a % mod) * (b % mod)) % mod
#define all(x) x.begin(),x.end()

map<char, int> mp;

int calc(char x, int y) {
  return (((y - mp[x]) % 4) + 4) % 4;
}

#define info tuple<int, int, int>
void solve() {
  mp['N'] = 0;mp['E'] = 1;mp['S'] = 2;mp['W'] = 3;
  int n,m;cin>>n>>m;
  vector<string> grid(n);
  for (int i = 0; i < n; i++) cin >> grid[i];
  priority_queue<info, vector<info>, greater<info>> pq;
  pq.push({0, 0, 0});
  vector<vector<int>> dist(n, vector<int>(m, INF));
  while (!pq.empty()) {
    auto [cost, i, j] = pq.top();pq.pop();
    if (cost > dist[i][j] || grid[i][j] == 'X') continue;
    dist[i][j] = cost;

    //     debug(cost);
    // debug(i);
    // debug(j);
    // cout << endl;

    for (int k = 0; k < 4; k++) {
      int nexti = i + di[k], nextj = j + dj[k];
      if (nexti >= 0 && nexti < n && nextj >= 0 && nextj < m && cost + calc(grid[i][j], k) < dist[nexti][nextj]) {
        if (!(nexti == n-1 && nextj == m-1) && grid[nexti][nextj] == 'X') continue; 
        dist[nexti][nextj] = cost + calc(grid[i][j], k);
        pq.push({cost + calc(grid[i][j], k), nexti, nextj});
      }
    }
  }

  cout << (dist[n-1][m-1] == INF ? -1 : dist[n-1][m-1]) << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(0);cin.tie(0);
  int t=1;
  while(t--) solve();

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 1 ms 348 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 1 ms 348 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 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 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 4 ms 600 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 5 ms 740 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 43 ms 3000 KB Output is correct
40 Correct 46 ms 3000 KB Output is correct
41 Correct 2 ms 2908 KB Output is correct
42 Correct 47 ms 3016 KB Output is correct
43 Correct 76 ms 9376 KB Output is correct
44 Correct 3 ms 2908 KB Output is correct