結果
| 問題 |
No.124 門松列(3)
|
| コンテスト | |
| ユーザー |
hiyokko2
|
| 提出日時 | 2015-01-12 00:16:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,366 bytes |
| コンパイル時間 | 691 ms |
| コンパイル使用メモリ | 88,272 KB |
| 実行使用メモリ | 814,628 KB |
| 最終ジャッジ日時 | 2024-06-22 04:10:26 |
| 合計ジャッジ時間 | 4,826 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | MLE * 1 -- * 25 |
ソースコード
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
/*
class Target
{
public:
vector <string> draw(int n)
{
}
};
*/
class Pos
{
public:
//書かれている数字
int num;
int x, y, cnt;
int pre;
Pos(int pnum, int px, int py, int pcnt, int ppre)
{
num = pnum;
x = px;
y = py;
cnt = pcnt;
pre = ppre;
}
};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main()
{
int W, H, M[100][100];
cin >> W >> H;
rep(i, H) rep(j, W) cin >> M[i][j];
bool flag = false;
queue<Pos> q;
q.push(Pos(M[0][0], 0, 0, 0, 0));
q.push(Pos(M[0][0], 0, 0, 0, 10));
while (!q.empty())
{
Pos now = q.front();
q.pop();
if (now.x == W - 1 && now.y == H - 1)
{
cout << now.cnt << endl;
flag = true;
break;
}
for (int i=0; i<4; i++)
{
int nx = now.x + dx[i];
int ny = now.y + dy[i];
if (0<=nx && nx<W && 0<=ny && ny<H && M[ny][nx] != now.pre)
{
Pos next = Pos(M[ny][nx], nx, ny, now.cnt + 1, now.num);
q.push(next);
}
}
}
if (!flag)
{
cout << -1 << endl;
}
return 0;
}
hiyokko2