結果

問題 No.340 雪の足跡
ユーザー 0w10w1
提出日時 2016-12-15 16:02:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,370 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 182,256 KB
実行使用メモリ 820,696 KB
最終ジャッジ日時 2023-08-20 07:37:06
合計ジャッジ時間 7,782 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
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;

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 ] )
      que.emplace( d + 1, ux + 1, uy );
    if( ux - 1 >= 0 and pathup[ ux - 1 ][ uy ] and not vis[ ux - 1 ][ uy ] )
      que.emplace( d + 1, ux - 1, uy );
    if( uy + 1 < W and pathright[ ux ][ uy ] and not vis[ ux ][ uy + 1 ] )
      que.emplace( d + 1, ux, uy + 1 );
    if( uy - 1 >= 0 and pathright[ ux ][ uy - 1 ] and not vis[ ux ][ uy - 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