結果

問題 No.340 雪の足跡
ユーザー しらっ亭しらっ亭
提出日時 2016-01-29 23:40:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,112 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 168,564 KB
実行使用メモリ 297,132 KB
最終ジャッジ日時 2023-10-21 17:33:35
合計ジャッジ時間 5,633 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
30,984 KB
testcase_01 AC 10 ms
30,996 KB
testcase_02 AC 11 ms
30,984 KB
testcase_03 AC 11 ms
30,984 KB
testcase_04 AC 10 ms
30,984 KB
testcase_05 AC 10 ms
30,980 KB
testcase_06 AC 18 ms
32,616 KB
testcase_07 AC 10 ms
30,984 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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