結果

問題 No.340 雪の足跡
ユーザー しらっ亭しらっ亭
提出日時 2016-01-30 01:03:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 386 ms / 1,000 ms
コード長 2,758 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 166,724 KB
実行使用メモリ 70,460 KB
最終ジャッジ日時 2023-10-21 17:41:14
合計ジャッジ時間 7,801 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
39,208 KB
testcase_01 AC 15 ms
39,208 KB
testcase_02 AC 14 ms
39,208 KB
testcase_03 AC 15 ms
39,208 KB
testcase_04 AC 15 ms
39,208 KB
testcase_05 AC 15 ms
39,208 KB
testcase_06 AC 15 ms
39,208 KB
testcase_07 AC 15 ms
39,208 KB
testcase_08 AC 15 ms
39,208 KB
testcase_09 AC 15 ms
39,208 KB
testcase_10 AC 15 ms
39,208 KB
testcase_11 AC 16 ms
39,240 KB
testcase_12 AC 16 ms
39,288 KB
testcase_13 AC 16 ms
39,332 KB
testcase_14 AC 34 ms
41,516 KB
testcase_15 AC 37 ms
41,636 KB
testcase_16 AC 28 ms
40,316 KB
testcase_17 AC 42 ms
42,020 KB
testcase_18 AC 39 ms
42,020 KB
testcase_19 AC 42 ms
42,020 KB
testcase_20 AC 181 ms
45,312 KB
testcase_21 AC 115 ms
39,240 KB
testcase_22 AC 17 ms
39,208 KB
testcase_23 AC 252 ms
70,456 KB
testcase_24 AC 138 ms
39,488 KB
testcase_25 AC 194 ms
52,880 KB
testcase_26 AC 40 ms
39,564 KB
testcase_27 AC 20 ms
39,216 KB
testcase_28 AC 41 ms
40,640 KB
testcase_29 AC 253 ms
57,372 KB
testcase_30 AC 181 ms
53,056 KB
testcase_31 AC 338 ms
67,768 KB
testcase_32 AC 386 ms
70,460 KB
testcase_33 AC 343 ms
70,460 KB
testcase_34 AC 383 ms
70,460 KB
testcase_35 AC 367 ms
70,460 KB
testcase_36 AC 354 ms
70,460 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |   scanf("%d %d %d", &W, &H, &N);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:50:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |     scanf("%d", &M);
      |     ~~~~~^~~~~~~~~~
main.cpp:53:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |       scanf("%d", B+j);
      |       ~~~~~^~~~~~~~~~~

ソースコード

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];
int VI[1010][1010];
int HI[1010][1010];

vector<int> E[1001010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  scanf("%d %d %d", &W, &H, &N);

  ZERO(VI);
  ZERO(HI);

  REP(i, N) {
    int M;
    scanf("%d", &M);
    int B[1010];
    REP(j, M+1) {
      scanf("%d", B+j);
    }
    REP(j, M) {
      int f = B[j];
      int t = B[j+1];
      int mi = MIN(f, t);
      int ma = MAX(f, t);

      if (f / W == t / W) {
        // yoko
        int l = mi % W;
        int r = ma % W;
        int y = mi / W;
        HI[y][l]++;
        HI[y][r]--;
      }
      else {
        // tate
        int b = mi / W;
        int t = ma / W;
        int x = mi % W;
        VI[b][x]++;
        VI[t][x]--;
      }
    }
  }

  REP(y, H) {
    REP(x, W) {
      if (x) HI[y][x] += HI[y][x-1];
      if (y) VI[y][x] += VI[y-1][x];
      if (HI[y][x]) {
        E[y*W+x].push_back(y*W+x+1);
        E[y*W+x+1].push_back(y*W+x);
      }
      if (VI[y][x]) {
        E[y*W+x].push_back(y*W+x+W);
        E[y*W+x+W].push_back(y*W+x);
      }
    }
  }

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

    auto& ep = E[p];
    int sz = SZ(ep);
    REP(i, sz) {
      int n = ep[i];
      if (c + 1 < C[n]) {
        C[n] = c + 1;
        q.push(n);
      }
    }
  }

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