結果

問題 No.340 雪の足跡
ユーザー y_mazuny_mazun
提出日時 2016-01-29 22:58:56
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,964 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 52,444 KB
実行使用メモリ 70,992 KB
最終ジャッジ日時 2023-10-21 17:15:03
合計ジャッジ時間 7,015 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
55,840 KB
testcase_01 AC 18 ms
51,476 KB
testcase_02 AC 19 ms
51,344 KB
testcase_03 AC 19 ms
51,472 KB
testcase_04 AC 19 ms
51,408 KB
testcase_05 AC 19 ms
51,404 KB
testcase_06 AC 19 ms
51,472 KB
testcase_07 AC 19 ms
51,428 KB
testcase_08 AC 19 ms
51,416 KB
testcase_09 AC 19 ms
51,468 KB
testcase_10 AC 19 ms
51,420 KB
testcase_11 AC 22 ms
51,808 KB
testcase_12 AC 22 ms
52,072 KB
testcase_13 AC 24 ms
52,468 KB
testcase_14 AC 344 ms
67,964 KB
testcase_15 AC 490 ms
68,672 KB
testcase_16 AC 174 ms
60,804 KB
testcase_17 AC 645 ms
70,992 KB
testcase_18 AC 484 ms
70,984 KB
testcase_19 AC 630 ms
70,992 KB
testcase_20 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:5:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 | inline int getInt(){ int s; scanf("%d", &s); return s; }
      |                             ~~~~~^~~~~~~~~~

ソースコード

diff #

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

const int inf = 1000000000;
set<int> s[1000][1000];
int dp[1000][1000];

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

int main(){
  const int w = getInt();
  const int h = getInt();
  const int n = getInt();

  REP(i,n){
    const int m = getInt();

    int pb = getInt();
    REP(j,m){
      const int px = pb % w;
      const int py = pb / w;

      const int b = getInt();
      const int x = b % w;
      const int y = b / w;

      if(px == x){
        const int mny = min(y, py);
        const int mxy = max(y, py);

        for(int y = mny; y < mxy; y++){
          s[y][x].insert((y + 1) * w + x);
          s[y + 1][x].insert(y * w + x);
        }
      }else{
        const int mnx = min(x, px);
        const int mxx = max(x, px);

        for(int x = mnx; x < mxx; x++){
          s[y][x].insert(y * w + x + 1);
          s[y][x + 1].insert(y * w + x);
        }
      }

      pb = b;
    }
  }

  queue<int> q;
  q.push(0);

  REP(i,h) REP(j,w) dp[i][j] = -1;
  dp[0][0] = 0;

  while(q.size()){
    const int pos = q.front(); q.pop();
    const int x = pos % w;
    const int y = pos / w;
    const int cost = dp[y][x];
    //printf("%d %d: %d\n", x, y, cost);
    dp[y][x] = cost;

    REP(i,4){
      const int xx = x + _dx[i];
      const int yy = y + _dy[i];

      if(!ISIN(xx, yy, w, h)) continue;
      if(dp[yy][xx] != -1) continue;
      if(!s[yy][xx].count(y * w + x)) continue;

      dp[yy][xx] = cost + 1;
      q.push(yy * w + xx);
    }
  }

  // REP(i,h){ REP(j,w) printf("%d ", dp[i][j]); puts(""); }

  const int ans = dp[h - 1][w - 1];
  if(ans == -1){
    puts("Odekakedekinai..");
  }else{
    printf("%d\n", ans);
  }

  return 0;
}
0