結果

問題 No.340 雪の足跡
ユーザー しらっ亭しらっ亭
提出日時 2016-01-30 00:32:40
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 2,076 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 166,544 KB
実行使用メモリ 814,480 KB
最終ジャッジ日時 2023-10-21 17:39:11
合計ジャッジ時間 7,631 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
30,992 KB
testcase_01 AC 11 ms
30,992 KB
testcase_02 AC 11 ms
30,996 KB
testcase_03 AC 11 ms
30,992 KB
testcase_04 AC 11 ms
30,996 KB
testcase_05 AC 12 ms
30,992 KB
testcase_06 AC 11 ms
30,992 KB
testcase_07 AC 11 ms
30,996 KB
testcase_08 AC 11 ms
30,996 KB
testcase_09 AC 11 ms
30,992 KB
testcase_10 AC 11 ms
30,996 KB
testcase_11 AC 15 ms
32,056 KB
testcase_12 AC 14 ms
31,624 KB
testcase_13 AC 16 ms
32,260 KB
testcase_14 AC 299 ms
81,500 KB
testcase_15 AC 423 ms
102,932 KB
testcase_16 AC 165 ms
69,692 KB
testcase_17 AC 686 ms
130,636 KB
testcase_18 AC 411 ms
109,160 KB
testcase_19 AC 690 ms
130,328 KB
testcase_20 MLE -
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];

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;
      }
    }
  }

  queue<int> q;
  
  FILL(C, 0x3f);
  C[0] = 0;
  q.push(0);

  while (!q.empty()) {
    int p = q.front();
    q.pop();
    int c = C[p];
    //_P("%d,%d\n", p, c);
    if (p == W * H - 1) {
      cout << c << '\n';
      return 0;
    }

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

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