結果

問題 No.340 雪の足跡
ユーザー kzyKTkzyKT
提出日時 2016-01-29 23:09:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,104 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 166,080 KB
実行使用メモリ 11,564 KB
最終ジャッジ日時 2023-10-21 17:21:58
合計ジャッジ時間 5,178 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 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 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 22 ms
6,648 KB
testcase_15 AC 28 ms
6,660 KB
testcase_16 AC 19 ms
6,496 KB
testcase_17 AC 39 ms
6,708 KB
testcase_18 AC 30 ms
6,708 KB
testcase_19 AC 39 ms
6,708 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

bool a[1000][1000][4];
void Main() {
  int n,m,k;
  cin >> m >> n >> k;
  rep(i,k) {
    int l,xx=-1,yy=-1;
    cin >> l;
    rep(j,l+1) {
      int z;
      cin >> z;
      int x2=z/m,y2=z%m;
      int x=xx,y=yy;
      if(xx!=-1) {
        while(x!=x2||y!=y2) {
          if(x==x2&&y<y2) a[x][y][1]=1,a[x][y+1][3]=1,y++;
          else if(x==x2&&y>y2) a[x][y][3]=1,a[x][y-1][1]=1,y--;
          else if(x<x2&&y==y2) a[x][y][2]=1,a[x+1][y][0]=1,x++;
          else a[x][y][0]=1,a[x-1][y][2]=1,x--;
        }
      }
      xx=x2,yy=y2;
    }
  }
  int d[n][m];
  rep(i,n)rep(j,m)d[i][j]=MAX;
  d[0][0]=0;
  queue<P> que;
  que.push(P(0,0));
  while(!que.empty()) {
    P p=que.front();que.pop();
    int nx=p.F,ny=p.S;
    rep(i,4) {
      if(!a[nx][ny][i]) continue;
      int x=nx+dx[i],y=ny+dy[i];
      if(d[x][y]<=d[nx][ny]+1) continue;
      d[x][y]=d[nx][ny]+1;
      que.push(P(x,y));
    }
  }
  if(d[n-1][m-1]==MAX) pr("Odekakedekinai..");
  else pr(d[n-1][m-1]);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}
0