結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-07-22 19:31:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
OLE
|
| 実行時間 | - |
| コード長 | 1,613 bytes |
| コンパイル時間 | 849 ms |
| コンパイル使用メモリ | 94,004 KB |
| 実行使用メモリ | 224,496 KB |
| 最終ジャッジ日時 | 2024-07-08 11:53:54 |
| 合計ジャッジ時間 | 13,644 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | OLE * 1 -- * 25 |
ソースコード
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int f[100][100];
bool kado(int a,int b,int c,int d){
cout << a << " " << b << " " << c;
if(d<2){
return true;
}
if( (c < a && a < b) || (b<a&&a<c)||(a<c&&c<b)||(b<c&&c<a) ){
return true;
}
return false;
}
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
//cout << setprecision(16);//
int W,H;
cin>>W>>H;
rep(i,H)rep(j,W){
cin>>f[i][j];//[y][x]
}
queue< vector<int> > q;
vector<int> now(5),next(5);
now[0] = 0;
now[1] = 0;
now[2] = -1;
now[3] = -1;
now[4] = 0;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
q.push( now );
while( !q.empty()){
now = q.front();q.pop();
next[2] = f[now[1]][now[0]];
next[3] = now[2];
next[4] = now[4] + 1;
rep(i,4){
next[0] = now[0] + dx[i];
next[1] = now[1] + dy[i];
if( 0 <= next[0] && next[0] < W &&
0 <= next[1] && next[1] < H){
if( true == kado(f[next[1]][next[0]],next[2],next[3],next[4]) ){
if( next[0] == W-1 && next[1] == H-1){
P(next[4]);
return 0;
}
if(next[4] <= W*H){
q.push(next);
}
}
}
}
}
P(-1);
return 0;
}
IL_msta