Submission #19287


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
using namespace std;

const int di[] = {+1,-1, 0, 0};
const int dj[] = { 0, 0,+1,-1};

int N, M;
vector<string> s;
bool visited[500][500];

bool visit(int i, int j) {
	if (!(0 <= i && i < N && 0 <= j && j < M)) return false;
	if (s[i][j] == '#') return false;
	if (s[i][j] == 'g') return true;
	if (visited[i][j]) return false;
	visited[i][j] = true;
	for (int k = 0; k < 4; ++ k) {
		if (visit(i+di[k], j+dj[k])) return true;
	}
	return false;
}

int main() {
	cin >> N >> M;
	s= vector<string>(N);
	int si = 0, sj = 0;
	int gi = 0, gj = 0;
	for (int i = 0; i < N; ++ i) {
		cin >> s[i];
		for (int j = 0; j < M; ++ j) {
			if (s[i][j] == 's') {
				si = i;
				sj = j;
			}
			if (s[i][j] == 'g') {
				gi = i;
				gj = j;
			}
		}
	}
	if (!visit(si, sj)) {
		cout << -1 << endl;
		return 0;
	}
	vector<vector<double> > a(N, vector<double>(M, 0));
	a[si][sj] = 1e+300;
	set<pair<int,int> > b;
	b.insert(make_pair(si,sj));
	double ans = 0;
	for (int t = 1; !b.empty(); ++ t) {
		vector<vector<double> > a0 = a;
		set<pair<int,int> > c;
		for (set<pair<int,int> >::iterator it = b.begin(); it != b.end(); ++ it) {
			int i = it->first;
			int j = it->second;
			for (int k = 0; k < 4; ++ k) {
				int ii = i + di[k];
				int jj = j + dj[k];
				if (!(0 <= ii && ii < N && 0 <= jj && jj < M)) continue;
				if (s[ii][jj] == '#') continue;
				double x = a0[i][j];
				if ('1' <= s[ii][jj] && s[ii][jj] <= '9') {
					x = min(x, (s[ii][jj]-'0')*pow(0.99, t));
				}
				if (x > a[ii][jj]) {
					a[ii][jj] = x;
					if (x >= ans) c.insert(make_pair(ii, jj));
				}
			}
		}
		ans = max(ans, a[gi][gj]);
		b = c;
	}
	printf("%.10f\n", ans);
}

Submission Info

Submission Time
Task C - 暗闇帰り道
User hasi
Language C++ (G++ 4.6.4)
Score 0
Code Size 1860 Byte
Status RE
Exec Time 5032 ms
Memory 14564 KB

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
AC × 54
TLE × 4
RE × 6
Set Name Test Cases
all 00_mini_01.txt, 00_mini_02.txt, 00_mini_03.txt, 00_mini_04.txt, 00_mini_05.txt, 00_sample_01.txt, 00_sample_02.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 01_rnd_20.txt, 02_maxrnd_01.txt, 02_maxrnd_02.txt, 02_maxrnd_03.txt, 02_maxrnd_04.txt, 02_maxrnd_05.txt, 02_maxrnd_06.txt, 02_maxrnd_07.txt, 02_maxrnd_08.txt, 02_maxrnd_09.txt, 02_maxrnd_10.txt, 02_maxrnd_11.txt, 02_maxrnd_12.txt, 02_maxrnd_13.txt, 02_maxrnd_14.txt, 02_maxrnd_15.txt, 02_maxrnd_16.txt, 02_maxrnd_17.txt, 02_maxrnd_18.txt, 02_maxrnd_19.txt, 03_hard_01.txt, 03_hard_02.txt, 03_hard_03.txt, 03_hard_04.txt, 03_hard_05.txt, 03_hard_06.txt, 03_hard_07.txt, 03_hard_08.txt, 04_open_01.txt, 04_open_02.txt, 05_minihard_01.txt, 05_minihard_02.txt, 05_minihard_03.txt, 05_minihard_04.txt, 05_minihard_05.txt, 05_minihard_06.txt, 05_minihard_07.txt, 05_minihard_08.txt
Case Name Status Exec Time Memory
00_mini_01.txt AC 21 ms 792 KB
00_mini_02.txt AC 22 ms 792 KB
00_mini_03.txt AC 20 ms 776 KB
00_mini_04.txt AC 20 ms 788 KB
00_mini_05.txt AC 21 ms 792 KB
00_sample_01.txt AC 20 ms 784 KB
00_sample_02.txt AC 20 ms 788 KB
01_rnd_01.txt AC 521 ms 12316 KB
01_rnd_02.txt AC 104 ms 4224 KB
01_rnd_03.txt AC 33 ms 1680 KB
01_rnd_04.txt AC 66 ms 2680 KB
01_rnd_05.txt AC 28 ms 1044 KB
01_rnd_06.txt AC 23 ms 1040 KB
01_rnd_07.txt AC 36 ms 1680 KB
01_rnd_08.txt AC 157 ms 4712 KB
01_rnd_09.txt AC 263 ms 5704 KB
01_rnd_10.txt AC 280 ms 4084 KB
01_rnd_11.txt AC 171 ms 3836 KB
01_rnd_12.txt AC 107 ms 3308 KB
01_rnd_13.txt AC 33 ms 1172 KB
01_rnd_14.txt AC 310 ms 4960 KB
01_rnd_15.txt AC 122 ms 3344 KB
01_rnd_16.txt AC 41 ms 1840 KB
01_rnd_17.txt AC 31 ms 1196 KB
01_rnd_18.txt AC 23 ms 792 KB
01_rnd_19.txt AC 24 ms 792 KB
01_rnd_20.txt AC 22 ms 812 KB
02_maxrnd_01.txt AC 366 ms 11368 KB
02_maxrnd_02.txt AC 250 ms 9452 KB
02_maxrnd_03.txt AC 411 ms 14564 KB
02_maxrnd_04.txt AC 532 ms 14064 KB
02_maxrnd_05.txt AC 404 ms 9964 KB
02_maxrnd_06.txt AC 1057 ms 11492 KB
02_maxrnd_07.txt AC 237 ms 9700 KB
02_maxrnd_08.txt AC 168 ms 7864 KB
02_maxrnd_09.txt AC 1150 ms 6228 KB
02_maxrnd_10.txt AC 360 ms 10632 KB
02_maxrnd_11.txt AC 1201 ms 10492 KB
02_maxrnd_12.txt AC 619 ms 9520 KB
02_maxrnd_13.txt AC 639 ms 6860 KB
02_maxrnd_14.txt AC 730 ms 8068 KB
02_maxrnd_15.txt AC 216 ms 5320 KB
02_maxrnd_16.txt AC 616 ms 6480 KB
02_maxrnd_17.txt AC 1477 ms 5644 KB
02_maxrnd_18.txt AC 36 ms 1140 KB
02_maxrnd_19.txt AC 38 ms 1020 KB
03_hard_01.txt RE 1835 ms 11268 KB
03_hard_02.txt RE 299 ms 11256 KB
03_hard_03.txt TLE 5032 ms 13080 KB
03_hard_04.txt TLE 5032 ms 13080 KB
03_hard_05.txt RE 298 ms 11260 KB
03_hard_06.txt RE 284 ms 11260 KB
03_hard_07.txt TLE 5032 ms 13088 KB
03_hard_08.txt TLE 5031 ms 13164 KB
04_open_01.txt RE 285 ms 11252 KB
04_open_02.txt RE 295 ms 11268 KB
05_minihard_01.txt AC 25 ms 792 KB
05_minihard_02.txt AC 23 ms 788 KB
05_minihard_03.txt AC 22 ms 780 KB
05_minihard_04.txt AC 23 ms 788 KB
05_minihard_05.txt AC 23 ms 792 KB
05_minihard_06.txt AC 23 ms 796 KB
05_minihard_07.txt AC 23 ms 792 KB
05_minihard_08.txt AC 23 ms 788 KB