Contest Duration: - (local time) (90 minutes) Back to Home

Submission #19322

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.swap(c);
}
printf("%.10f\n", ans);
}
```

#### Submission Info

Submission Time 2012-05-27 21:19:17+0900 C - 暗闇帰り道 hasi C++ (G++ 4.6.4) 0 1864 Byte RE 5031 ms 14548 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 788 KB
00_mini_03.txt AC 23 ms 736 KB
00_mini_04.txt AC 21 ms 792 KB
00_mini_05.txt AC 21 ms 788 KB
00_sample_01.txt AC 21 ms 756 KB
00_sample_02.txt AC 21 ms 784 KB
01_rnd_01.txt AC 464 ms 12328 KB
01_rnd_02.txt AC 103 ms 4224 KB
01_rnd_03.txt AC 32 ms 1632 KB
01_rnd_04.txt AC 60 ms 2680 KB
01_rnd_05.txt AC 26 ms 1020 KB
01_rnd_06.txt AC 22 ms 1044 KB
01_rnd_07.txt AC 35 ms 1624 KB
01_rnd_08.txt AC 148 ms 4712 KB
01_rnd_09.txt AC 243 ms 5824 KB
01_rnd_10.txt AC 273 ms 4080 KB
01_rnd_11.txt AC 162 ms 3820 KB
01_rnd_12.txt AC 97 ms 3308 KB
01_rnd_13.txt AC 31 ms 1180 KB
01_rnd_14.txt AC 318 ms 4948 KB
01_rnd_15.txt AC 140 ms 3332 KB
01_rnd_16.txt AC 49 ms 1884 KB
01_rnd_17.txt AC 30 ms 1136 KB
01_rnd_18.txt AC 22 ms 760 KB
01_rnd_19.txt AC 24 ms 788 KB
01_rnd_20.txt AC 22 ms 788 KB
02_maxrnd_01.txt AC 374 ms 11372 KB
02_maxrnd_02.txt AC 263 ms 9440 KB
02_maxrnd_03.txt AC 369 ms 14548 KB
02_maxrnd_04.txt AC 481 ms 14056 KB
02_maxrnd_05.txt AC 449 ms 9972 KB
02_maxrnd_06.txt AC 844 ms 11504 KB
02_maxrnd_07.txt AC 198 ms 9664 KB
02_maxrnd_08.txt AC 204 ms 7864 KB
02_maxrnd_09.txt AC 864 ms 6196 KB
02_maxrnd_10.txt AC 263 ms 10636 KB
02_maxrnd_11.txt AC 763 ms 10508 KB
02_maxrnd_12.txt AC 502 ms 9512 KB
02_maxrnd_13.txt AC 585 ms 6800 KB
02_maxrnd_14.txt AC 591 ms 8072 KB
02_maxrnd_15.txt AC 272 ms 5328 KB
02_maxrnd_16.txt AC 554 ms 6440 KB
02_maxrnd_17.txt AC 1386 ms 5644 KB
02_maxrnd_18.txt AC 36 ms 1152 KB
02_maxrnd_19.txt AC 35 ms 1016 KB
03_hard_01.txt RE 277 ms 11260 KB
03_hard_02.txt RE 277 ms 11256 KB
03_hard_03.txt TLE 5031 ms 13064 KB
03_hard_04.txt TLE 5031 ms 13068 KB
03_hard_05.txt RE 284 ms 11272 KB
03_hard_06.txt RE 283 ms 11264 KB
03_hard_07.txt TLE 5030 ms 13068 KB
03_hard_08.txt TLE 5031 ms 13128 KB
04_open_01.txt RE 280 ms 11272 KB
04_open_02.txt RE 283 ms 11284 KB
05_minihard_01.txt AC 23 ms 884 KB
05_minihard_02.txt AC 24 ms 908 KB
05_minihard_03.txt AC 23 ms 792 KB
05_minihard_04.txt AC 23 ms 756 KB
05_minihard_05.txt AC 23 ms 764 KB
05_minihard_06.txt AC 21 ms 788 KB
05_minihard_07.txt AC 21 ms 788 KB
05_minihard_08.txt AC 21 ms 792 KB