Submission #3767700


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int R, C;
  cin >> R >> C;
  vector<vector<int>> v(R, vector<int>(C));
  pii s, t;
  rep(i, 0, R) rep(j, 0, C) {
    char c;
    cin >> c;
    if (c == 's') {
      s = pii(i, j);
    } else if (c == 't') {
      t = pii(i, j);
    } else {
      v[i][j] = c - '0';
    }
  }
  using State = tuple<int, int, int>;
  priority_queue<State, vector<State>, greater<State>> pq;
  pq.push(State(0, s.fi, s.se));
  map<pii, int> mp;
  mp[s] = 0;
  int dx[] = {0, 1, 1, 0, -1, -1},
      dy[][6] = {{1, 0, -1, -1, -1, 0}, {1, 1, 0, -1, 0, 1}};
  auto inrange = [&](int x, int y) {
    return 0 <= x and x < R and 0 <= y and y < C;
  };
  while (pq.size()) {
    int cost, x, y;
    tie(cost, x, y) = pq.top();
    pq.pop();
    if (cost > mp[pii(x, y)])
      continue;

    rep(i, 0, 6) {
      int a = x + dx[i], b = y + dy[x % 2][i];
      if (inrange(a, b)) {
        if (not mp.count(pii(a, b))) {
          mp[pii(a, b)] = INF;
        }
        if (chmin(mp[pii(a, b)], cost + v[a][b])) {
          pq.push(State(mp[pii(a, b)], a, b));
        }
      }
    }
  }
  cout << mp[t] << endl;

  return 0;
}

Submission Info

Submission Time
Task B - Office Ninja
User norma
Language C++14 (GCC 5.4.1)
Score 100
Code Size 3804 Byte
Status AC
Exec Time 15 ms
Memory 1152 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 28
Set Name Test Cases
All 001-sample-01.txt, 002-sample-02.txt, 003-minimum-01.txt, 004-random-01.txt, 005-random-02.txt, 006-random-03.txt, 007-random-04.txt, 008-random-05.txt, 009-random-06.txt, 010-random-07.txt, 011-random-08.txt, 012-random-09.txt, 013-random-10.txt, 014-random-11.txt, 015-random-12.txt, 016-random-13.txt, 017-random-14.txt, 018-random-15.txt, 019-random-16.txt, 020-random-17.txt, 021-random-18.txt, 022-random-19.txt, 023-random-20.txt, 024-maximum-01.txt, 025-maximum-02.txt, 026-maximum-03.txt, 027-maximum-04.txt, 999-handmade-01.txt
Case Name Status Exec Time Memory
001-sample-01.txt AC 1 ms 256 KB
002-sample-02.txt AC 1 ms 256 KB
003-minimum-01.txt AC 1 ms 256 KB
004-random-01.txt AC 5 ms 512 KB
005-random-02.txt AC 3 ms 384 KB
006-random-03.txt AC 3 ms 384 KB
007-random-04.txt AC 1 ms 256 KB
008-random-05.txt AC 10 ms 768 KB
009-random-06.txt AC 2 ms 256 KB
010-random-07.txt AC 2 ms 384 KB
011-random-08.txt AC 1 ms 256 KB
012-random-09.txt AC 3 ms 384 KB
013-random-10.txt AC 2 ms 256 KB
014-random-11.txt AC 5 ms 512 KB
015-random-12.txt AC 1 ms 256 KB
016-random-13.txt AC 2 ms 256 KB
017-random-14.txt AC 7 ms 640 KB
018-random-15.txt AC 1 ms 256 KB
019-random-16.txt AC 9 ms 640 KB
020-random-17.txt AC 1 ms 256 KB
021-random-18.txt AC 6 ms 512 KB
022-random-19.txt AC 9 ms 768 KB
023-random-20.txt AC 2 ms 256 KB
024-maximum-01.txt AC 15 ms 1024 KB
025-maximum-02.txt AC 15 ms 1024 KB
026-maximum-03.txt AC 15 ms 1024 KB
027-maximum-04.txt AC 15 ms 1024 KB
999-handmade-01.txt AC 13 ms 1152 KB