結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-01-21 20:37:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,750 bytes |
| コンパイル時間 | 1,127 ms |
| コンパイル使用メモリ | 114,172 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2024-06-22 23:32:36 |
| 合計ジャッジ時間 | 2,448 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 WA * 3 |
ソースコード
#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 < 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;
}