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

Submission #18754

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;
vector< vector<double> > D(N, vector<double>(M, 0));
D[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("%.9f\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;
if ('1' <= s[i][j] && s[i][j] <= '9') {
double x = min(x0, (s[i][j]-'0')*pow(0.99, t+1));
if (x > D[i][j]) {
D[i][j] = x;
Q.push(make_pair(x, make_pair(t+1, make_pair(i, j))));
}
} else {
double x = x0;
if (x > D[i][j]) {
D[i][j] = x;
Q.push(make_pair(x, make_pair(t+1, make_pair(i, j))));
}
}
}
}
}
```

#### Submission Info

Submission Time 2012-05-27 20:31:54+0900 C - 暗闇帰り道 hasi C++ (G++ 4.6.4) 0 1887 Byte WA 321 ms 12984 KB

#### Judge Result

Set Name all
Score / Max Score 0 / 100
Status
 AC × 16 WA × 42 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 780 KB
00_mini_02.txt AC 21 ms 784 KB
00_mini_03.txt AC 21 ms 792 KB
00_mini_04.txt AC 21 ms 788 KB
00_mini_05.txt AC 22 ms 764 KB
00_sample_01.txt AC 21 ms 792 KB
00_sample_02.txt AC 21 ms 792 KB
01_rnd_01.txt WA 166 ms 11524 KB
01_rnd_02.txt WA 40 ms 3680 KB
01_rnd_03.txt WA 26 ms 1392 KB
01_rnd_04.txt WA 32 ms 2608 KB
01_rnd_05.txt WA 22 ms 1016 KB
01_rnd_06.txt WA 21 ms 908 KB
01_rnd_07.txt WA 25 ms 1416 KB
01_rnd_08.txt WA 50 ms 3952 KB
01_rnd_09.txt WA 57 ms 4468 KB
01_rnd_10.txt WA 64 ms 3068 KB
01_rnd_11.txt WA 48 ms 3064 KB
01_rnd_12.txt WA 38 ms 2808 KB
01_rnd_13.txt WA 23 ms 1044 KB
01_rnd_14.txt WA 76 ms 3824 KB
01_rnd_15.txt WA 48 ms 2548 KB
01_rnd_16.txt AC 25 ms 1272 KB
01_rnd_17.txt AC 30 ms 1152 KB
01_rnd_18.txt AC 22 ms 792 KB
01_rnd_19.txt AC 23 ms 788 KB
01_rnd_20.txt AC 22 ms 816 KB
02_maxrnd_01.txt WA 77 ms 9800 KB
02_maxrnd_02.txt WA 66 ms 7844 KB
02_maxrnd_03.txt WA 95 ms 12984 KB
02_maxrnd_04.txt WA 108 ms 12412 KB
02_maxrnd_05.txt WA 80 ms 8120 KB
02_maxrnd_06.txt WA 163 ms 9916 KB
02_maxrnd_07.txt WA 57 ms 7888 KB
02_maxrnd_08.txt WA 48 ms 5876 KB
02_maxrnd_09.txt WA 138 ms 4464 KB
02_maxrnd_10.txt WA 70 ms 8828 KB
02_maxrnd_11.txt WA 137 ms 8760 KB
02_maxrnd_12.txt WA 88 ms 7672 KB
02_maxrnd_13.txt WA 82 ms 4988 KB
02_maxrnd_14.txt WA 110 ms 6136 KB
02_maxrnd_15.txt WA 45 ms 3320 KB
02_maxrnd_16.txt WA 85 ms 4476 KB
02_maxrnd_17.txt WA 75 ms 3580 KB
02_maxrnd_18.txt AC 34 ms 1148 KB
02_maxrnd_19.txt AC 35 ms 1020 KB
03_hard_01.txt RE 321 ms 11252 KB
03_hard_02.txt RE 278 ms 11252 KB
03_hard_03.txt WA 76 ms 11004 KB
03_hard_04.txt WA 78 ms 10996 KB
03_hard_05.txt RE 276 ms 11248 KB
03_hard_06.txt RE 277 ms 11256 KB
03_hard_07.txt WA 74 ms 10996 KB
03_hard_08.txt WA 76 ms 11008 KB
04_open_01.txt RE 277 ms 11268 KB
04_open_02.txt RE 277 ms 11260 KB
05_minihard_01.txt WA 22 ms 868 KB
05_minihard_02.txt WA 21 ms 816 KB
05_minihard_03.txt AC 22 ms 764 KB
05_minihard_04.txt AC 20 ms 788 KB
05_minihard_05.txt WA 21 ms 780 KB
05_minihard_06.txt WA 22 ms 788 KB
05_minihard_07.txt WA 24 ms 916 KB
05_minihard_08.txt WA 22 ms 760 KB