結果

問題 No.340 雪の足跡
ユーザー imulanimulan
提出日時 2016-02-12 16:31:22
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,661 bytes
コンパイル時間 1,812 ms
コンパイル使用メモリ 164,424 KB
実行使用メモリ 816,516 KB
最終ジャッジ日時 2023-10-22 02:36:07
合計ジャッジ時間 7,714 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
31,152 KB
testcase_01 AC 12 ms
31,152 KB
testcase_02 AC 11 ms
31,152 KB
testcase_03 AC 12 ms
31,152 KB
testcase_04 AC 11 ms
31,152 KB
testcase_05 AC 11 ms
31,152 KB
testcase_06 AC 11 ms
31,152 KB
testcase_07 AC 11 ms
31,152 KB
testcase_08 AC 12 ms
31,152 KB
testcase_09 AC 11 ms
31,152 KB
testcase_10 AC 12 ms
31,152 KB
testcase_11 AC 15 ms
32,216 KB
testcase_12 AC 15 ms
31,792 KB
testcase_13 AC 17 ms
32,420 KB
testcase_14 AC 214 ms
81,696 KB
testcase_15 AC 293 ms
103,132 KB
testcase_16 AC 131 ms
69,896 KB
testcase_17 AC 462 ms
130,844 KB
testcase_18 AC 358 ms
109,448 KB
testcase_19 AC 474 ms
130,524 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, const char**)’:
main.cpp:22:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |   scanf(" %d %d %d",&w,&h,&n);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:25:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |     scanf(" %d",&m);
      |     ~~~~~^~~~~~~~~~
main.cpp:28:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |     rep(j,m+1) scanf(" %d", &b[j]);
      |                ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

const int INF=100000000;

//隣接リスト
vector<int> G[1000000];

int main(int argc, char const *argv[]) {
  int i,j;

  //input
  int w,h,n;
  scanf(" %d %d %d",&w,&h,&n);
  rep(i,n){
    int m;
    scanf(" %d",&m);

    vector<int> b(m+1);
    rep(j,m+1) scanf(" %d", &b[j]);

    //隣接リストを構成
    rep(j,m){
      //sからdへ直線的に進む
      int s=b[j],d=b[j+1];

      //進行方向決定
      int dx=0,dy=0;
      if(s%w==d%w){//縦方向
        if(s<d) dy=1;
        else dy=-1;
      }
      else{//横方向
        if(s<d) dx=1;
        else dx=-1;
      }

      //dにたどり着くまでsから進行する
      while(s!=d){
        int nxt=s+(w*dy+dx);
        //printf("now i,j= %d,%d : s=%d, nxt=%d\n",i,j,s,nxt);

        G[s].pb(nxt);
        G[nxt].pb(s);
        s=nxt;
      }
    }
  }
  /*
  rep(i,w*h){
    printf("%d: ",i);
    rep(j,G[i].size()) printf(" %d",G[i][j]);
    printf("\n");
  }
  */

  //地点0からの距離
  int dist[1000000];
  rep(i,1000000) dist[i]=INF;
  dist[0]=0;

  //BFS
  queue<int> que;
  que.push(0);
  while(!que.empty()){
    int v=que.front();
    que.pop();
    rep(i,G[v].size()){
      if(dist[G[v][i]] > dist[v]+1){
        dist[G[v][i]]=dist[v]+1;
        que.push(G[v][i]);
      }
    }
  }

  //output
  if(dist[w*h-1]==INF) printf("Odekakedekinai..\n");
  else printf("%d\n",dist[w*h-1]);
  return 0;
}
0