結果

問題 No.340 雪の足跡
ユーザー 0w10w1
提出日時 2016-12-15 16:03:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 1,000 ms
コード長 2,494 bytes
コンパイル時間 4,541 ms
コンパイル使用メモリ 182,804 KB
実行使用メモリ 15,504 KB
最終ジャッジ日時 2023-08-20 07:37:15
合計ジャッジ時間 9,142 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 14 ms
4,436 KB
testcase_18 AC 11 ms
4,436 KB
testcase_19 AC 15 ms
4,728 KB
testcase_20 AC 122 ms
15,164 KB
testcase_21 AC 80 ms
4,380 KB
testcase_22 AC 13 ms
14,816 KB
testcase_23 AC 135 ms
15,504 KB
testcase_24 AC 111 ms
15,272 KB
testcase_25 AC 118 ms
14,880 KB
testcase_26 AC 21 ms
4,380 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 18 ms
4,376 KB
testcase_29 AC 156 ms
10,340 KB
testcase_30 AC 101 ms
8,932 KB
testcase_31 AC 189 ms
14,152 KB
testcase_32 AC 223 ms
15,180 KB
testcase_33 AC 167 ms
15,200 KB
testcase_34 AC 215 ms
15,192 KB
testcase_35 AC 144 ms
15,184 KB
testcase_36 AC 142 ms
15,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int W, H, N;
vvi pathup;
vvi pathright;

void init(){
  cin >> W >> H >> N;
  pathup = pathright = vvi( H, vi( W ) );
  for( int i = 0; i < N; ++i ){
    int M; cin >> M;
    int u; cin >> u;
    for( int j = 0; j < M; ++j ){
      int v; cin >> v;
      int ux = u / W, uy = u % W;
      int vx = v / W, vy = v % W;
      if( not ( ux <= vx and uy <= vy ) )
        swap( ux, vx ),
        swap( uy, vy );
      // cout << ux << " " << uy << " " << vx << " " << vy << endl;
      if( ux == vx )
        ++pathright[ ux ][ uy ],
        --pathright[ vx ][ vy ];
      else
        ++pathup[ ux ][ uy ],
        --pathup[ vx ][ vy ];
      u = v;
    }
  }
}

void preprocess(){
  for( int i = 0; i < H; ++i )
    for( int j = 0; j < W; ++j ){
      if( i + 1 < H )
        pathup[ i + 1 ][ j ] += pathup[ i ][ j ];
      if( j + 1 < W )
        pathright[ i ][ j + 1 ] += pathright[ i ][ j ];
    }
  vvi vis( H, vi( W ) );
  vis[ 0 ][ 0 ] = 1;
  queue< tuple< int, int, int > > que;
  que.emplace( 0, 0, 0 );
  while( not que.empty() ){
    int d, ux, uy; tie( d, ux, uy ) = que.front(); que.pop();
    if( ux == H - 1 and uy == W - 1 )
      cout << d << endl, exit( 0 );
    if( ux + 1 < H and pathup[ ux ][ uy ] and not vis[ ux + 1 ][ uy ] )
      vis[ ux + 1 ][ uy ] = 1,
      que.emplace( d + 1, ux + 1, uy );
    if( ux - 1 >= 0 and pathup[ ux - 1 ][ uy ] and not vis[ ux - 1 ][ uy ] )
      vis[ ux - 1 ][ uy ] = 1,
      que.emplace( d + 1, ux - 1, uy );
    if( uy + 1 < W and pathright[ ux ][ uy ] and not vis[ ux ][ uy + 1 ] )
      vis[ ux ][ uy + 1 ] = 1,
      que.emplace( d + 1, ux, uy + 1 );
    if( uy - 1 >= 0 and pathright[ ux ][ uy - 1 ] and not vis[ ux ][ uy - 1 ] )
      vis[ ux ][ uy - 1 ] = 1,
      que.emplace( d + 1, ux, uy - 1 );
  }
  cout << "Odekakedekinai.." << endl;
}

void solve(){

}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0