結果

問題 No.124 門松列(3)
ユーザー tkzw_21tkzw_21
提出日時 2015-01-13 17:00:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,306 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 144,688 KB
実行使用メモリ 9,896 KB
最終ジャッジ日時 2023-09-04 05:11:23
合計ジャッジ時間 2,829 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,740 KB
testcase_01 AC 4 ms
8,240 KB
testcase_02 AC 4 ms
8,184 KB
testcase_03 AC 9 ms
9,896 KB
testcase_04 AC 5 ms
8,216 KB
testcase_05 AC 6 ms
8,220 KB
testcase_06 AC 4 ms
8,180 KB
testcase_07 AC 5 ms
8,232 KB
testcase_08 AC 4 ms
8,180 KB
testcase_09 AC 4 ms
8,188 KB
testcase_10 AC 4 ms
8,220 KB
testcase_11 AC 5 ms
8,224 KB
testcase_12 AC 4 ms
8,176 KB
testcase_13 AC 4 ms
8,228 KB
testcase_14 AC 5 ms
8,272 KB
testcase_15 AC 5 ms
8,276 KB
testcase_16 WA -
testcase_17 AC 4 ms
8,248 KB
testcase_18 WA -
testcase_19 AC 4 ms
8,288 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 4 ms
8,248 KB
testcase_23 AC 5 ms
8,244 KB
testcase_24 AC 5 ms
8,232 KB
testcase_25 AC 5 ms
8,196 KB
testcase_26 AC 4 ms
8,244 KB
testcase_27 AC 4 ms
8,188 KB
testcase_28 AC 6 ms
8,256 KB
testcase_29 AC 6 ms
8,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF INT_MAX / 2
#define MOD 1000000007

using namespace std;

typedef pair<int,int> PII;
typedef pair<int,pair<int,int>> PIPII;
typedef long long ll;

bool isKadomatsuSequence(int a2,int a1,int a0){
    if((a1 < a0 && a1 < a2 || a1 > a2 && a1 > a0) && a2 != a0)return true;
    return false;
}

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};

int m[101][101];
bool used[101][101][11][11];
int memo[101][101][11][11];

int w,h;
int dfs(int y,int x,int prev2,int prev1){
    if(y<0||y>=h||x<0||x>=w|| prev2 != -1 && !isKadomatsuSequence(prev2,prev1,m[y][x]) || used[y][x][prev2+1][prev1+1])return INF;
    if(y == h-1 && x == w-1)return 0;
    if(memo[y][x][prev2+1][prev1+1] != -1)return memo[y][x][prev2+1][prev1+1];
    //cout << y << " " << x << endl;
    int ret = INF;
    for(int i=0;i<4;i++){
        used[y][x][prev2+1][prev1+1] = true;
        ret = min(ret,dfs(y+dy[i],x+dx[i],prev1,m[y][x]));
        used[y][x][prev2+1][prev1+1] = false;
    }
    return memo[y][x][prev2+1][prev1+1] = ret+1;
}

int main(void) {
    cin >> w >> h;
    memset(memo,-1,sizeof(memo));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> m[i][j];
        }
    }
    int ans = dfs(0,0,-1,-1);
    if(ans>=INF)cout << -1 << endl;
    else cout << ans << endl;
}
0