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

Submission #19107

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;
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;
double ans = 0;
for (int t = 1; t <= 1000; ++ t) {
vector<vector<double> > a0 = a;
for (int i = 0; i < N; ++ i) {
for (int j = 0; j < M; ++ j) {
if (s[i][j] == '#') continue;
if (a0[i][j] == 0) continue;
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));
}
a[ii][jj] = max(a[ii][jj], x);
}
}
}
ans = max(ans, a[gi][gj]);
}
printf("%.10f\n", ans);
}
```

#### Submission Info

Submission Time 2012-05-27 20:57:54+0900 C - 暗闇帰り道 hasi C++ (G++ 4.6.4) 0 1715 Byte RE 5053 ms 14496 KB

#### Judge Result

Set Name all
Score / Max Score 0 / 100
Status
 AC × 32 TLE × 21 RE × 11
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 788 KB
00_mini_02.txt AC 22 ms 788 KB
00_mini_03.txt AC 23 ms 792 KB
00_mini_04.txt AC 23 ms 764 KB
00_mini_05.txt AC 22 ms 792 KB
00_sample_01.txt AC 24 ms 788 KB
00_sample_02.txt AC 26 ms 728 KB
01_rnd_01.txt TLE 5039 ms 12320 KB
01_rnd_02.txt RE 0 ms 4160 KB
01_rnd_03.txt AC 2685 ms 1592 KB
01_rnd_04.txt AC 3867 ms 2640 KB
01_rnd_05.txt AC 1021 ms 1020 KB
01_rnd_06.txt AC 453 ms 1016 KB
01_rnd_07.txt AC 2425 ms 1608 KB
01_rnd_08.txt TLE 5031 ms 4712 KB
01_rnd_09.txt RE 0 ms 5752 KB
01_rnd_10.txt TLE 5032 ms 4136 KB
01_rnd_11.txt RE 0 ms 3788 KB
01_rnd_12.txt TLE 5031 ms 3236 KB
01_rnd_13.txt AC 987 ms 1152 KB
01_rnd_14.txt RE 0 ms 4936 KB
01_rnd_15.txt TLE 5032 ms 3340 KB
01_rnd_16.txt AC 3805 ms 1840 KB
01_rnd_17.txt AC 32 ms 1160 KB
01_rnd_18.txt AC 23 ms 788 KB
01_rnd_19.txt AC 24 ms 788 KB
01_rnd_20.txt AC 24 ms 792 KB
02_maxrnd_01.txt RE 0 ms 11464 KB
02_maxrnd_02.txt TLE 5032 ms 9372 KB
02_maxrnd_03.txt TLE 5035 ms 14496 KB
02_maxrnd_04.txt TLE 5053 ms 13940 KB
02_maxrnd_05.txt TLE 5031 ms 9860 KB
02_maxrnd_06.txt TLE 5033 ms 11476 KB
02_maxrnd_07.txt TLE 5032 ms 9600 KB
02_maxrnd_08.txt TLE 5032 ms 7868 KB
02_maxrnd_09.txt TLE 5032 ms 6044 KB
02_maxrnd_10.txt TLE 5032 ms 10560 KB
02_maxrnd_11.txt TLE 5035 ms 10284 KB
02_maxrnd_12.txt TLE 5035 ms 9496 KB
02_maxrnd_13.txt TLE 5031 ms 6852 KB
02_maxrnd_14.txt TLE 5032 ms 8104 KB
02_maxrnd_15.txt TLE 5037 ms 5360 KB
02_maxrnd_16.txt TLE 5031 ms 6548 KB
02_maxrnd_17.txt TLE 5033 ms 5736 KB
02_maxrnd_18.txt AC 38 ms 1148 KB
02_maxrnd_19.txt AC 37 ms 1016 KB
03_hard_01.txt RE 290 ms 11260 KB
03_hard_02.txt RE 285 ms 11260 KB
03_hard_03.txt AC 4398 ms 13080 KB
03_hard_04.txt AC 4377 ms 13068 KB
03_hard_05.txt RE 280 ms 11252 KB
03_hard_06.txt RE 284 ms 11260 KB
03_hard_07.txt AC 4452 ms 13080 KB
03_hard_08.txt AC 4663 ms 13060 KB
04_open_01.txt RE 286 ms 11264 KB
04_open_02.txt RE 292 ms 11256 KB
05_minihard_01.txt AC 132 ms 784 KB
05_minihard_02.txt AC 134 ms 764 KB
05_minihard_03.txt AC 125 ms 776 KB
05_minihard_04.txt AC 67 ms 796 KB
05_minihard_05.txt AC 134 ms 864 KB
05_minihard_06.txt AC 133 ms 784 KB
05_minihard_07.txt AC 65 ms 764 KB
05_minihard_08.txt AC 68 ms 784 KB