結果

問題 No.340 雪の足跡
ユーザー しらっ亭
提出日時 2016-01-29 23:40:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 2,112 bytes
コンパイル時間 1,340 ms
コンパイル使用メモリ 166,508 KB
実行使用メモリ 298,172 KB
最終ジャッジ日時 2024-09-21 18:48:26
合計ジャッジ時間 4,848 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 3 TLE * 1 -- * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define MIN(a,b) (a < b ? a : b)
#define MAX(a,b) (a > b ? a : b)
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define bitcount(b) __builtin_popcount(b)
#define GCD(a,b) (__gcd(a,b))
#define GCD3(a,b,c) (GCD(GCD(a,b), c))
#define LCM(a,b) (a/GCD(a,b)*b)
#define LCM3(a,b,c) LCM(LCM(a,b),c)
#define MOD 1000000007
template<class T> inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
typedef long long ll;
// -------------------------------------

typedef pair<int, int> II;

int W, H, N;
int C[1001010];

II toYX(int b) {
  return {b / W, b % W};
}

vector<int> E[1001010];

int main() {
  cin >> W >> H >> N;

  REP(i, N) {
    int M;
    cin >> M;
    int B[1010];
    REP(j, M+1) {
      cin >> B[j];
    }
    REP(j, M) {
      int f = B[j];
      int t = B[j+1];
      int x = MIN(f, t);
      int y = MAX(f, t);
      int d = (x / W == y / W) ? 1 : W;

      while (x != y) {
        E[x].push_back(x+d);
        E[x+d].push_back(x);
        x+=d;
      }
    }
  }

  priority_queue<II, vector<II>, greater<II> > q;
  
  FILL(C, 0x3f);
  q.push({0, 0});

  while (!q.empty()) {
    int c = q.top().first;
    int p = q.top().second;
    if (p == W * H - 1) {
      cout << c << '\n';
      return 0;
    }
    q.pop();

    if (C[p] <= c) continue;

    ITR(it, E[p]) {
      q.push({c + 1, *it});
    }
  }

  cout << "Odekakedekinai.." << '\n';
  return 0;
}
0