Submission #1301106


Source Code Expand

Copy
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t H,W,K;
char map[1000][1000];
bool ok[1000][1000];
void func(int h, int w, int k)
{
	if (h < 0 || H <= h || w < 0 || W <= w) { return; }
	if (k < 0) { return; }
	if (ok[h][w]) { return; }
	if (map[h][w] == '#') { return; }
	ok[h][w] = true;
	func(h - 1, w, k - 1);
	func(h + 1, w, k - 1);
	func(h, w - 1, k - 1);
	func(h, w + 1, k - 1);
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> H>>W>>K;
	for (size_t i = 0; i < H; i++)
	{
		in >> map[i];
	}
	int sx=0, sy = 0;
	for (size_t i = 0; i < H; i++)
	{
		for (size_t w = 0; w < W; w++)
		{
			if (map[i][w] == 'S') {
				sx = w; sy = i; map[i][w] = '.';
			}
		}
	}

	{
		std::vector<std::pair<int, int>> que;
		std::vector<std::pair<int, int>> quenext;
		quenext.emplace_back(sx, sy);
		for (int count = 0; count <= K; count++)
		{
			std::swap(quenext, que);
			for (auto& i : que) {
				auto w = i.first,h=i.second;
				if (h < 0 || H <= h || w < 0 || W <= w) { continue; }
				if (ok[h][w]) { continue; }
				if (map[h][w] == '#') { continue; }
				ok[h][w] = true;
				quenext.emplace_back(w - 1, h);
				quenext.emplace_back(w + 1, h);
				quenext.emplace_back(w, h - 1);
				quenext.emplace_back(w, h + 1);
			}
		}
	}

	int res = H*W;
	for (int i = 0; i < H; i++)
	{
		for (int w = 0; w < W; w++)
		{
			if (ok[i][w]) {
				res = std::min(res, 1 + (std::min({ i,H - i - 1,w,W - w - 1 })+K-1)/K);
			}
		}
	}
	std::cout << res << std::endl;

	return 0;
}
#endif

Submission Info

Submission Time
Task C - Closed Rooms
User eiya
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1990 Byte
Status TLE
Exec Time 2104 ms
Memory 27696 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 44
TLE × 2
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 3 ms 1024 KB
in10.txt AC 3 ms 1024 KB
in11.txt AC 3 ms 1024 KB
in12.txt AC 3 ms 1024 KB
in13.txt AC 3 ms 1024 KB
in14.txt AC 3 ms 1024 KB
in15.txt AC 3 ms 1024 KB
in16.txt AC 3 ms 1024 KB
in17.txt AC 3 ms 1024 KB
in18.txt AC 3 ms 1024 KB
in19.txt AC 3 ms 1024 KB
in2.txt AC 3 ms 1024 KB
in20.txt AC 2 ms 1024 KB
in21.txt AC 1 ms 256 KB
in22.txt AC 1 ms 256 KB
in23.txt AC 3 ms 1024 KB
in24.txt AC 3 ms 1024 KB
in25.txt AC 3 ms 1024 KB
in26.txt AC 6 ms 1536 KB
in27.txt AC 3 ms 1024 KB
in28.txt AC 231 ms 5732 KB
in29.txt AC 1101 ms 18008 KB
in3.txt AC 3 ms 1024 KB
in30.txt AC 33 ms 3012 KB
in31.txt AC 3 ms 1024 KB
in32.txt AC 3 ms 1024 KB
in33.txt TLE 2104 ms 27696 KB
in34.txt TLE 2104 ms 27696 KB
in35.txt AC 3 ms 1152 KB
in36.txt AC 4 ms 1024 KB
in37.txt AC 3 ms 1024 KB
in38.txt AC 3 ms 1024 KB
in39.txt AC 3 ms 1024 KB
in4.txt AC 19 ms 1024 KB
in40.txt AC 3 ms 1024 KB
in5.txt AC 67 ms 1024 KB
in6.txt AC 3 ms 1024 KB
in7.txt AC 3 ms 1024 KB
in8.txt AC 3 ms 1024 KB
in9.txt AC 3 ms 1024 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB