Submission #18857


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <map>
#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;
	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 (!visit(si, sj)) {
		cout << -1 << endl;
		return 0;
	}
	priority_queue<pair<double, pair<int, pair<int,int> > > > Q;
	map<pair<int, pair<int,int> >, double> D;
	D[make_pair(0, make_pair(si, sj))] = 1e+300;
	Q.push(make_pair(1e+300, make_pair(0, make_pair(si, sj))));
	while (!Q.empty()) {
		double x0 = Q.top().first;
		int t = Q.top().second.first;
		int i0 = Q.top().second.second.first;
		int j0 = Q.top().second.second.second;
		Q.pop();
		if (s[i0][j0] == 'g') {
			printf("%.10f\n", x0);
			break;
		}
		for (int k = 0; k < 4; ++ k) {
			int i = i0 + di[k];
			int j = j0 + dj[k];
			if (!(0 <= i && i < N && 0 <= j && j < M)) continue;
			if (s[i][j] == '#') continue;
			double x = x0;
			pair<int, pair<int,int> > n = make_pair(t+1, make_pair(i, j));
			if ('1' <= s[i][j] && s[i][j] <= '9') {
				x = min(x, (s[i][j]-'0')*pow(0.99, t+1));
			}
			if (x > D[n]) {
				D[n] = x;
				Q.push(make_pair(x, n));
			}
		}
	}
}

Submission Info

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

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
AC × 30
TLE × 17
MLE × 11
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 23 ms 756 KB
00_mini_02.txt AC 20 ms 788 KB
00_mini_03.txt AC 21 ms 780 KB
00_mini_04.txt AC 22 ms 820 KB
00_mini_05.txt AC 21 ms 792 KB
00_sample_01.txt AC 21 ms 784 KB
00_sample_02.txt AC 20 ms 784 KB
01_rnd_01.txt TLE 5058 ms 220956 KB
01_rnd_02.txt MLE 2366 ms 105368 KB
01_rnd_03.txt AC 121 ms 7208 KB
01_rnd_04.txt AC 1301 ms 59296 KB
01_rnd_05.txt AC 108 ms 6828 KB
01_rnd_06.txt AC 41 ms 2488 KB
01_rnd_07.txt AC 105 ms 7344 KB
01_rnd_08.txt MLE 4309 ms 165528 KB
01_rnd_09.txt TLE 5052 ms 194840 KB
01_rnd_10.txt TLE 5054 ms 195992 KB
01_rnd_11.txt TLE 5051 ms 198172 KB
01_rnd_12.txt MLE 2802 ms 109864 KB
01_rnd_13.txt AC 860 ms 35236 KB
01_rnd_14.txt TLE 5050 ms 200992 KB
01_rnd_15.txt TLE 5048 ms 194088 KB
01_rnd_16.txt AC 35 ms 1676 KB
01_rnd_17.txt AC 29 ms 1176 KB
01_rnd_18.txt AC 23 ms 768 KB
01_rnd_19.txt AC 26 ms 768 KB
01_rnd_20.txt AC 22 ms 788 KB
02_maxrnd_01.txt TLE 5052 ms 218904 KB
02_maxrnd_02.txt MLE 3452 ms 143012 KB
02_maxrnd_03.txt TLE 5055 ms 211104 KB
02_maxrnd_04.txt MLE 4836 ms 208792 KB
02_maxrnd_05.txt TLE 5050 ms 208228 KB
02_maxrnd_06.txt TLE 5053 ms 210720 KB
02_maxrnd_07.txt AC 1327 ms 59944 KB
02_maxrnd_08.txt AC 442 ms 25772 KB
02_maxrnd_09.txt TLE 5052 ms 218784 KB
02_maxrnd_10.txt MLE 3138 ms 132008 KB
02_maxrnd_11.txt TLE 5053 ms 209436 KB
02_maxrnd_12.txt TLE 5052 ms 215068 KB
02_maxrnd_13.txt TLE 5050 ms 213404 KB
02_maxrnd_14.txt TLE 5053 ms 211580 KB
02_maxrnd_15.txt MLE 3241 ms 118692 KB
02_maxrnd_16.txt TLE 5053 ms 202860 KB
02_maxrnd_17.txt TLE 5055 ms 205988 KB
02_maxrnd_18.txt AC 34 ms 1136 KB
02_maxrnd_19.txt AC 37 ms 1020 KB
03_hard_01.txt RE 290 ms 11252 KB
03_hard_02.txt RE 293 ms 11228 KB
03_hard_03.txt MLE 3971 ms 244328 KB
03_hard_04.txt MLE 3960 ms 244344 KB
03_hard_05.txt RE 290 ms 11264 KB
03_hard_06.txt RE 278 ms 11256 KB
03_hard_07.txt MLE 4665 ms 244024 KB
03_hard_08.txt MLE 4797 ms 244152 KB
04_open_01.txt RE 292 ms 11256 KB
04_open_02.txt RE 276 ms 11252 KB
05_minihard_01.txt AC 87 ms 5680 KB
05_minihard_02.txt AC 100 ms 6832 KB
05_minihard_03.txt AC 55 ms 3448 KB
05_minihard_04.txt AC 73 ms 4468 KB
05_minihard_05.txt AC 98 ms 6320 KB
05_minihard_06.txt AC 103 ms 6580 KB
05_minihard_07.txt AC 73 ms 3836 KB
05_minihard_08.txt AC 94 ms 4980 KB