結果

問題 No.340 雪の足跡
ユーザー rickythetarickytheta
提出日時 2016-01-29 22:59:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,970 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 167,384 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 17:16:05
合計ジャッジ時間 6,425 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 24 ms
4,348 KB
testcase_15 AC 30 ms
4,348 KB
testcase_16 AC 22 ms
4,348 KB
testcase_17 AC 40 ms
4,348 KB
testcase_18 AC 31 ms
4,348 KB
testcase_19 AC 39 ms
4,348 KB
testcase_20 RE -
testcase_21 AC 983 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 62 ms
4,348 KB
testcase_27 AC 12 ms
4,348 KB
testcase_28 AC 54 ms
4,348 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define V_MAX 100010
#define INF 100000000

int g[V_MAX];
// right, up, left, down
int dir[4] = {1,2,4,8};
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int w,h;

void add_edge(int src,int dst){
  if(src>dst)swap(src,dst);
  int sx,sy,tx,ty;
  sx = src%w;
  sy = src/w;
  tx = dst%w;
  ty = dst/w;
  if(sx==tx){
    FOR(i,sy,ty){
      g[sx+i*w] |= dir[1];
      g[sx+(i+1)*w] |= dir[3];
    }
  }else{
    FOR(i,sx,tx){
      g[sy*w+i] |= dir[0];
      g[sy*w+i+1] |= dir[2];
    }
  }
}

int main(){
  // w,h<1e3
  // |V| = wh < 1e6
  // n < 1e3
  // m < 1e3
  // |E| = nm < 1e6
  int n;
  cin>>w>>h>>n;
  while(n--){
    int m;
    cin>>m;
    int bef;
    cin>>bef;
    REP(i,m){
      int cur;
      cin>>cur;
      add_edge(bef,cur);
      bef = cur;
    }
  }
  queue<pii> Q;
  int s = 0;
  int t = w*h-1;
  Q.push(make_pair(0,0));
  int res = -1;
  vector<bool> used(w*h,false);
  used[s] = true;
  while(!Q.empty()){
    pii P = Q.front(); Q.pop();
    int pos = P.first;
    int wei = P.second;
    int x = pos%w;
    int y = pos/w;
    REP(i,4){
      if(!(g[pos] & dir[i]))continue;
      int tx = x+dx[i];
      int ty = y+dy[i];
      int tpos = ty*w+tx;
      if(tpos<0 || tpos>=w*h)continue;
      if(used[tpos])continue;
      if(tpos == t){
        cout<<(wei+1)<<endl;
        return 0;
      }
      used[tpos] = true;
      Q.push(make_pair(tpos,wei+1));
    }
  }
  cout<<"Odekakedekinai.."<<endl;
  return 0;
}
0