結果

問題 No.124 門松列(3)
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-01-11 23:52:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,044 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 96,584 KB
実行使用メモリ 7,528 KB
最終ジャッジ日時 2023-09-04 04:27:20
合計ジャッジ時間 3,278 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,268 KB
testcase_01 WA -
testcase_02 AC 5 ms
7,248 KB
testcase_03 AC 11 ms
7,324 KB
testcase_04 AC 12 ms
7,320 KB
testcase_05 AC 5 ms
7,360 KB
testcase_06 AC 5 ms
7,252 KB
testcase_07 AC 5 ms
7,216 KB
testcase_08 AC 5 ms
7,468 KB
testcase_09 AC 4 ms
7,232 KB
testcase_10 AC 4 ms
7,284 KB
testcase_11 AC 4 ms
7,252 KB
testcase_12 AC 4 ms
7,512 KB
testcase_13 AC 5 ms
7,236 KB
testcase_14 AC 5 ms
7,332 KB
testcase_15 AC 4 ms
7,212 KB
testcase_16 WA -
testcase_17 AC 5 ms
7,332 KB
testcase_18 AC 4 ms
7,408 KB
testcase_19 AC 5 ms
7,228 KB
testcase_20 WA -
testcase_21 AC 4 ms
7,284 KB
testcase_22 AC 5 ms
7,524 KB
testcase_23 AC 4 ms
7,504 KB
testcase_24 AC 6 ms
7,424 KB
testcase_25 AC 4 ms
7,256 KB
testcase_26 AC 4 ms
7,332 KB
testcase_27 AC 6 ms
7,260 KB
testcase_28 AC 5 ms
7,372 KB
testcase_29 AC 5 ms
7,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000009

int dp[100][100][10][10];
int d[101][101];

int isK(int a, int b, int c){
  if(a==b||b==c)return 0;
  int d = b;
  vector<int> v;
  v.pb(a);v.pb(b);v.pb(c);
  sort(all(v));
  if(d==v[0]||d==v[2])return 1;
  return 0;
}

int main(){
  static int dx[4] = {-1, 0, 0, 1};
  static int dy[4] = {0, -1, 1, 0};
  int w,h;
  cin>>w>>h;
  rep(y,0,h){
    rep(x,0,w){
      char a;
      cin>>a;
      d[y][x] = a-'0';
    }
  }
  clr(dp,0);
  queue<int> qy,qx;
  queue<int> a1,a2;
  queue<int> qc;
  qy.push(0);
  qx.push(0);
  a1.push(d[0][0]);
  a2.push(-1);
  qc.push(0);
  while(!qy.empty()){
    int yy = qy.front();qy.pop();
    int xx = qx.front();qx.pop();
    int aa1 = a1.front();a1.pop();
    int aa2 = a2.front();a2.pop();
    int cc = qc.front();qc.pop();
    if(yy==h-1&&xx==w-1){
      cout << cc << endl;
      return 0;
    }
    rep(i,0,4){
      int cy = yy+dy[i];
      int cx = xx+dx[i];
      if(0>cy||cy>=h)continue;
      if(0>cx||cx>=w)continue;
      if(aa2==-1){
        qy.push(cy);
        qx.push(cx);
        a1.push(d[cy][cx]);
        a2.push(aa1);
        qc.push(cc+1);
      }
      else{
        if(dp[cy][cx][aa1][aa2]!=0)continue;
        dp[cy][cx][aa1][aa2]=1;
        if(isK(d[cy][cx],aa1,aa2) == 1){
          qy.push(cy);
          qx.push(cx);
          a1.push(d[cy][cx]);
          a2.push(aa1);
          qc.push(cc+1);
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
0