結果

問題 No.124 門松列(3)
ユーザー mamekinmamekin
提出日時 2015-01-21 20:46:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,763 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 115,796 KB
実行使用メモリ 11,268 KB
最終ジャッジ日時 2023-09-05 02:45:25
合計ジャッジ時間 2,379 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
10,940 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 18 ms
10,892 KB
testcase_04 AC 17 ms
10,896 KB
testcase_05 AC 17 ms
11,092 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 7 ms
6,416 KB
testcase_24 AC 9 ms
7,608 KB
testcase_25 AC 9 ms
7,648 KB
testcase_26 AC 4 ms
5,108 KB
testcase_27 AC 3 ms
4,504 KB
testcase_28 AC 17 ms
11,268 KB
testcase_29 AC 16 ms
10,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

int main()
{
    int w, h;
    cin >> w >> h;

    vector<vector<int> > m(h+2, vector<int>(w+2, -1));
    for(int y=1; y<=h; ++y){
        for(int x=1; x<=w; ++x){
            cin >> m[y][x];
        }
    }

    vector<vector<vector<vector<bool> > > > check(h+2, vector<vector<vector<bool> > >(w+2, vector<vector<bool> >(10, vector<bool>(10, false))));
    queue<tuple<int, int, int, int> > q;
    check[1][1][0][m[1][1]] = 1;
    q.push(make_tuple(1, 1, 0, m[1][1]));

    int ret = 0;
    while(!q.empty()){
        int n = q.size();
        while(--n >= 0){
            int y, x, a, b;
            tie(y, x, a, b) = q.front();
            q.pop();
            if(y == h && x == w){
                cout << ret << endl;
                return 0;
            }

            for(int i=0; i<4; ++i){
                int y2 = y + dy[i];
                int x2 = x + dx[i];
                int c = m[y2][x2];
                if(c == -1)
                    continue;
                if(a != 0 && !(a != c && ((a < b && b > c) || (a > b && b < c))))
                    continue;

                if(!check[y2][x2][b][c]){
                    check[y2][x2][b][c] = true;
                    q.push(make_tuple(y2,x2, b, c));
                }
            }
        }
        ++ ret;
    }

    cout << -1 << endl;
    return 0;
}
0