Submission #19480


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];

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;
			}
		}
	}
	queue<pair<int,int> > Q;
	visited[si][sj] = true;
	Q.push(make_pair(si,sj));
	while (!Q.empty()) {
		int i0 = Q.front().first;
		int j0 = Q.front().second;
		Q.pop();
		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;
			if (s[i][j] == 'g') goto start;
			if (visited[i][j]) continue;
			visited[i][j] = true;
			Q.push(make_pair(i, j));
		}
	}
	cout << -1 << endl;
	return 0;
	
	start:;
	
	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.swap(c);
	}
	printf("%.10f\n", ans);
}

Submission Info

Submission Time
Task C - 暗闇帰り道
User hasi
Language C++ (G++ 4.6.4)
Score 0
Code Size 2007 Byte
Status TLE
Exec Time 5030 ms
Memory 5452 KB

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
AC × 60
TLE × 4
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 764 KB
00_mini_02.txt AC 21 ms 788 KB
00_mini_03.txt AC 21 ms 792 KB
00_mini_04.txt AC 21 ms 888 KB
00_mini_05.txt AC 21 ms 792 KB
00_sample_01.txt AC 21 ms 792 KB
00_sample_02.txt AC 21 ms 792 KB
01_rnd_01.txt AC 536 ms 4348 KB
01_rnd_02.txt AC 103 ms 2488 KB
01_rnd_03.txt AC 30 ms 1244 KB
01_rnd_04.txt AC 61 ms 1488 KB
01_rnd_05.txt AC 26 ms 1016 KB
01_rnd_06.txt AC 22 ms 912 KB
01_rnd_07.txt AC 34 ms 1396 KB
01_rnd_08.txt AC 148 ms 2928 KB
01_rnd_09.txt AC 237 ms 3888 KB
01_rnd_10.txt AC 284 ms 3560 KB
01_rnd_11.txt AC 149 ms 2656 KB
01_rnd_12.txt AC 95 ms 2072 KB
01_rnd_13.txt AC 30 ms 1020 KB
01_rnd_14.txt AC 289 ms 3468 KB
01_rnd_15.txt AC 146 ms 2480 KB
01_rnd_16.txt AC 47 ms 1812 KB
01_rnd_17.txt AC 30 ms 1052 KB
01_rnd_18.txt AC 22 ms 768 KB
01_rnd_19.txt AC 24 ms 788 KB
01_rnd_20.txt AC 22 ms 784 KB
02_maxrnd_01.txt AC 322 ms 5192 KB
02_maxrnd_02.txt AC 258 ms 5264 KB
02_maxrnd_03.txt AC 393 ms 5192 KB
02_maxrnd_04.txt AC 496 ms 5412 KB
02_maxrnd_05.txt AC 414 ms 5228 KB
02_maxrnd_06.txt AC 877 ms 5400 KB
02_maxrnd_07.txt AC 172 ms 5140 KB
02_maxrnd_08.txt AC 168 ms 5152 KB
02_maxrnd_09.txt AC 897 ms 5448 KB
02_maxrnd_10.txt AC 249 ms 5280 KB
02_maxrnd_11.txt AC 812 ms 5452 KB
02_maxrnd_12.txt AC 533 ms 5396 KB
02_maxrnd_13.txt AC 462 ms 5424 KB
02_maxrnd_14.txt AC 530 ms 5384 KB
02_maxrnd_15.txt AC 259 ms 5136 KB
02_maxrnd_16.txt AC 549 ms 5260 KB
02_maxrnd_17.txt AC 1130 ms 5264 KB
02_maxrnd_18.txt AC 35 ms 1012 KB
02_maxrnd_19.txt AC 35 ms 1028 KB
03_hard_01.txt AC 809 ms 5256 KB
03_hard_02.txt AC 881 ms 5240 KB
03_hard_03.txt TLE 5030 ms 5248 KB
03_hard_04.txt TLE 5029 ms 5256 KB
03_hard_05.txt AC 754 ms 5248 KB
03_hard_06.txt AC 899 ms 5256 KB
03_hard_07.txt TLE 5030 ms 5252 KB
03_hard_08.txt TLE 5030 ms 5268 KB
04_open_01.txt AC 837 ms 5256 KB
04_open_02.txt AC 1067 ms 5360 KB
05_minihard_01.txt AC 23 ms 820 KB
05_minihard_02.txt AC 24 ms 780 KB
05_minihard_03.txt AC 21 ms 788 KB
05_minihard_04.txt AC 22 ms 788 KB
05_minihard_05.txt AC 22 ms 792 KB
05_minihard_06.txt AC 27 ms 812 KB
05_minihard_07.txt AC 23 ms 792 KB
05_minihard_08.txt AC 23 ms 788 KB