結果

問題 No.402 最も海から遠い場所
ユーザー kurenai3110kurenai3110
提出日時 2016-07-22 23:48:15
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,234 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 69,980 KB
実行使用メモリ 43,904 KB
最終ジャッジ日時 2024-04-24 06:20:12
合計ジャッジ時間 8,420 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 28 ms
5,376 KB
testcase_17 AC 298 ms
20,352 KB
testcase_18 AC 1,634 ms
38,656 KB
testcase_19 AC 457 ms
38,784 KB
testcase_20 TLE -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

bool tof,tof2;
int h, w;
pair<int, int> nx;

int solve(int cnt, vector<vector<int> > &land, pair<int,int> nx) {
	tof2 = false;
	int mn, mx;
	for (int i = nx.first; i < nx.second; i++) {
		for (int j = 1; j < w + 1; j++) {
			if (land[i][j] == cnt) {
				tof = false;
				for (int a = -1; a < 2; a++) {
					for (int b = -1; b < 2; b++) {
						if (land[i + a][j + b] < cnt) {
							tof = true;
							break;
						}
					}
					if (tof) break;
				}
				if (!tof) {
					land[i][j]++;
					if (!tof2) mn = i;
					mx = i;
					tof2 = true;
				}

			}
		}
	}
	if (!tof2) return cnt;

	nx = make_pair(mn, mx);
	cnt = solve(++cnt, land ,nx);

	return cnt;
}

int main()
{
	cin >> h >> w;
	vector<vector<int> > land;
	land.resize(h + 2);
	for (int i = 0; i < h + 2; i++) {
		if (i == 0 || i == h + 1) land[i].resize(w+2);
		else {
			land[i].resize(w + 2);
		}
	}

	for (int i = 1; i < h + 1; i++) {
		for (int j = 1; j < w + 1; j++) {
			char tmp;
			cin >> tmp;
			if (tmp == '.') land[i][j] = 0;
			else if (tmp == '#') land[i][j] = 1;
		}
	}
	int cnt = 1;

	nx = make_pair(1, h + 1);
	cout << solve(cnt, land,nx) << endl;

    return 0;
}
0