結果

問題 No.124 門松列(3)
ユーザー IL_mstaIL_msta
提出日時 2015-07-22 19:31:36
言語 C++11
(gcc 11.4.0)
結果
OLE  
実行時間 -
コード長 1,613 bytes
コンパイル時間 1,957 ms
コンパイル使用メモリ 94,020 KB
実行使用メモリ 229,008 KB
最終ジャッジ日時 2023-09-22 21:19:08
合計ジャッジ時間 15,053 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0