結果

問題 No.124 門松列(3)
ユーザー koyoprokoyopro
提出日時 2015-10-03 18:42:27
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,103 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 149,352 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 01:49:42
合計ジャッジ時間 4,443 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 RE -
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i, n) for(int i=0; i<(n); i++)

int W,H;
int M[11][11];
bool ch[11][11];
bool isKadomatsu(int a, int b, int c) {
    if (a == b) return false;
    if (a == c) return false;
    if (b == c) return false;
    int l[] = {a, b, c};
    sort(l, l+3);
    // 2番目は真ん中ではいけない
    if (l[1] == b) return false;
    return true;
}
int dfs(int x, int y, vector<int> s) {
    if (x == W-1 && y == H-1) return 0;
    int dxy[] = {0, 1, 0, -1, 0};
    int minc = 100000;
    s.push_back(M[x][y]);
    ch[x][y] = true;
    REP(i,4) {
        int nx = x + dxy[i];
        int ny = y + dxy[i+1];
        if (nx<0||W<=nx||ny<0||H<=ny) continue;
        if (ch[nx][ny]) continue;
        if (s.size()>=2 && !isKadomatsu(s[s.size()-2], s[s.size()-1], M[nx][ny])) continue;
        minc = min(minc, 1 + dfs(nx, ny, s));
    }
    ch[x][y] = false;
    return minc;
}
signed main()
{
    cin>>W>>H;
    REP(y,H)REP(x,W) cin >> M[x][y];

    vector<int> s;
    int ans = dfs(0, 0, s);
    cout << (ans<1000 ? ans : -1) << endl;

    return 0;
}
0