Submission #19231


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) {
		bool flag = true;
		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]) {
					if (x > ans) flag = false;
					a[ii][jj] = x;
					c.insert(make_pair(ii, jj));
				}
			}
		}
		if (flag) break;
		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 1920 Byte
Status RE
Exec Time 5033 ms
Memory 14572 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 22 ms 768 KB
00_mini_02.txt AC 22 ms 784 KB
00_mini_03.txt AC 21 ms 792 KB
00_mini_04.txt AC 22 ms 796 KB
00_mini_05.txt AC 20 ms 792 KB
00_sample_01.txt AC 22 ms 780 KB
00_sample_02.txt AC 20 ms 788 KB
01_rnd_01.txt AC 520 ms 12420 KB
01_rnd_02.txt AC 129 ms 4220 KB
01_rnd_03.txt AC 35 ms 1640 KB
01_rnd_04.txt AC 84 ms 2672 KB
01_rnd_05.txt AC 28 ms 1052 KB
01_rnd_06.txt AC 26 ms 1072 KB
01_rnd_07.txt AC 38 ms 1660 KB
01_rnd_08.txt AC 189 ms 4708 KB
01_rnd_09.txt AC 291 ms 5704 KB
01_rnd_10.txt AC 369 ms 4080 KB
01_rnd_11.txt AC 192 ms 3844 KB
01_rnd_12.txt AC 123 ms 3312 KB
01_rnd_13.txt AC 34 ms 1172 KB
01_rnd_14.txt AC 345 ms 4960 KB
01_rnd_15.txt AC 136 ms 3368 KB
01_rnd_16.txt AC 34 ms 1868 KB
01_rnd_17.txt AC 30 ms 1144 KB
01_rnd_18.txt AC 21 ms 788 KB
01_rnd_19.txt AC 23 ms 792 KB
01_rnd_20.txt AC 23 ms 764 KB
02_maxrnd_01.txt AC 377 ms 11364 KB
02_maxrnd_02.txt AC 324 ms 9556 KB
02_maxrnd_03.txt AC 418 ms 14572 KB
02_maxrnd_04.txt AC 536 ms 14056 KB
02_maxrnd_05.txt AC 431 ms 9960 KB
02_maxrnd_06.txt AC 1100 ms 11508 KB
02_maxrnd_07.txt AC 238 ms 9704 KB
02_maxrnd_08.txt AC 180 ms 8004 KB
02_maxrnd_09.txt AC 891 ms 6232 KB
02_maxrnd_10.txt AC 337 ms 10632 KB
02_maxrnd_11.txt AC 879 ms 10500 KB
02_maxrnd_12.txt AC 526 ms 9512 KB
02_maxrnd_13.txt AC 613 ms 6816 KB
02_maxrnd_14.txt AC 646 ms 8076 KB
02_maxrnd_15.txt AC 261 ms 5320 KB
02_maxrnd_16.txt AC 578 ms 6452 KB
02_maxrnd_17.txt AC 1081 ms 5624 KB
02_maxrnd_18.txt AC 36 ms 1144 KB
02_maxrnd_19.txt AC 35 ms 1140 KB
03_hard_01.txt RE 285 ms 11260 KB
03_hard_02.txt RE 281 ms 11256 KB
03_hard_03.txt TLE 5032 ms 13076 KB
03_hard_04.txt TLE 5032 ms 13064 KB
03_hard_05.txt RE 281 ms 11248 KB
03_hard_06.txt RE 281 ms 11264 KB
03_hard_07.txt TLE 5033 ms 13068 KB
03_hard_08.txt TLE 5032 ms 13080 KB
04_open_01.txt RE 283 ms 11264 KB
04_open_02.txt RE 281 ms 11252 KB
05_minihard_01.txt AC 24 ms 796 KB
05_minihard_02.txt AC 23 ms 796 KB
05_minihard_03.txt AC 23 ms 760 KB
05_minihard_04.txt AC 22 ms 792 KB
05_minihard_05.txt AC 22 ms 788 KB
05_minihard_06.txt AC 24 ms 796 KB
05_minihard_07.txt AC 23 ms 792 KB
05_minihard_08.txt AC 22 ms 788 KB