Submission #19690


Source Code Expand

Copy
#include <iostream>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(n) REP(i,n)

const int dx[] = { 1, -1, 0, 0 };
const int dy[] = { 0, 0, -1, 1 };
const int MAXN=512;
char C[MAXN][MAXN];
double U[MAXN][MAXN];
int W,H;

typedef pair<int,int> pii;

int main()
{
    cin>>H>>W; rep(H) cin>>C[i];

    int sx,sy,gx,gy; REP(y,H) REP(x,W)
    {
        if( C[y][x] == 's' ){ sx=x; sy=y; C[y][x]='#'; }
        if( C[y][x] == 'g' ){ gx=x; gy=y; }
    }

    U[sy][sx]=MAXN*MAXN+1;

    queue<pii> Q; Q.push(pii(1,sx+sy*MAXN)); while(!Q.empty())
    {
        const int t = Q.front().first;
        const int x = Q.front().second%MAXN;
        const int y = Q.front().second/MAXN;

        Q.pop(); rep(4)
        {
            const int nx = x+dx[i];
            const int ny = y+dy[i];
            if(nx<0||ny<0||nx>=W||ny>=H) continue;
            if(C[ny][nx]=='#') continue;

            double s1 = (C[ny][nx]=='g'?U[y][x]:(C[ny][nx]-'0')*pow(0.99,t));
            double s2 = min(s1,U[y][x]);

            if(U[ny][nx]<s2){ U[ny][nx]=s2; if(C[ny][nx]!='g') Q.push(pii(t+1,nx+ny*MAXN)); }
        }
    }

    if(abs(U[gy][gx])<(1e-9)) printf("-1\n"); else printf("%0.20lf\n",U[gy][gx]);

    return 0;
}

Submission Info

Submission Time
Task C - 暗闇帰り道
User mitsuchie
Language C++ (G++ 4.6.4)
Score 0
Code Size 1377 Byte
Status WA
Exec Time 158 ms
Memory 3068 KB

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
AC × 60
WA × 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 23 ms 784 KB
00_mini_02.txt AC 29 ms 736 KB
00_mini_03.txt AC 22 ms 768 KB
00_mini_04.txt AC 21 ms 788 KB
00_mini_05.txt AC 23 ms 788 KB
00_sample_01.txt AC 22 ms 788 KB
00_sample_02.txt AC 22 ms 796 KB
01_rnd_01.txt AC 111 ms 2552 KB
01_rnd_02.txt AC 65 ms 2292 KB
01_rnd_03.txt AC 37 ms 1020 KB
01_rnd_04.txt AC 40 ms 1532 KB
01_rnd_05.txt AC 29 ms 1040 KB
01_rnd_06.txt AC 23 ms 884 KB
01_rnd_07.txt AC 40 ms 2668 KB
01_rnd_08.txt AC 81 ms 2812 KB
01_rnd_09.txt AC 115 ms 2548 KB
01_rnd_10.txt AC 100 ms 2688 KB
01_rnd_11.txt AC 71 ms 1784 KB
01_rnd_12.txt AC 56 ms 1668 KB
01_rnd_13.txt AC 27 ms 920 KB
01_rnd_14.txt AC 71 ms 2176 KB
01_rnd_15.txt AC 46 ms 1652 KB
01_rnd_16.txt AC 34 ms 1380 KB
01_rnd_17.txt AC 38 ms 1932 KB
01_rnd_18.txt AC 23 ms 760 KB
01_rnd_19.txt AC 24 ms 912 KB
01_rnd_20.txt AC 22 ms 1048 KB
02_maxrnd_01.txt AC 136 ms 2936 KB
02_maxrnd_02.txt AC 142 ms 3060 KB
02_maxrnd_03.txt AC 146 ms 3068 KB
02_maxrnd_04.txt AC 142 ms 3060 KB
02_maxrnd_05.txt AC 154 ms 3064 KB
02_maxrnd_06.txt AC 149 ms 3064 KB
02_maxrnd_07.txt AC 148 ms 3064 KB
02_maxrnd_08.txt AC 154 ms 3044 KB
02_maxrnd_09.txt AC 151 ms 3068 KB
02_maxrnd_10.txt AC 158 ms 3044 KB
02_maxrnd_11.txt AC 148 ms 3060 KB
02_maxrnd_12.txt AC 139 ms 3060 KB
02_maxrnd_13.txt AC 133 ms 2936 KB
02_maxrnd_14.txt AC 109 ms 2936 KB
02_maxrnd_15.txt AC 92 ms 2944 KB
02_maxrnd_16.txt AC 73 ms 2940 KB
02_maxrnd_17.txt AC 62 ms 2944 KB
02_maxrnd_18.txt AC 36 ms 1400 KB
02_maxrnd_19.txt AC 35 ms 1372 KB
03_hard_01.txt AC 77 ms 2928 KB
03_hard_02.txt AC 81 ms 2932 KB
03_hard_03.txt WA 55 ms 2560 KB
03_hard_04.txt WA 57 ms 2948 KB
03_hard_05.txt AC 78 ms 2936 KB
03_hard_06.txt AC 79 ms 2944 KB
03_hard_07.txt WA 55 ms 2560 KB
03_hard_08.txt WA 57 ms 2932 KB
04_open_01.txt AC 65 ms 2936 KB
04_open_02.txt AC 128 ms 2944 KB
05_minihard_01.txt AC 23 ms 920 KB
05_minihard_02.txt AC 21 ms 916 KB
05_minihard_03.txt AC 21 ms 912 KB
05_minihard_04.txt AC 22 ms 916 KB
05_minihard_05.txt AC 23 ms 916 KB
05_minihard_06.txt AC 21 ms 916 KB
05_minihard_07.txt AC 24 ms 912 KB
05_minihard_08.txt AC 21 ms 920 KB