Submission #19626


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.9f\n",U[gy][gx]);

    return 0;
}

Submission Info

Submission Time
Task C - 暗闇帰り道
User mitsuchie
Language C++ (G++ 4.6.4)
Score 0
Code Size 1375 Byte
Status WA
Exec Time 150 ms
Memory 3080 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 22 ms 784 KB
00_mini_02.txt AC 20 ms 788 KB
00_mini_03.txt AC 22 ms 820 KB
00_mini_04.txt AC 21 ms 788 KB
00_mini_05.txt AC 21 ms 788 KB
00_sample_01.txt AC 20 ms 788 KB
00_sample_02.txt AC 23 ms 784 KB
01_rnd_01.txt AC 109 ms 2556 KB
01_rnd_02.txt AC 64 ms 2296 KB
01_rnd_03.txt AC 38 ms 1048 KB
01_rnd_04.txt AC 39 ms 1540 KB
01_rnd_05.txt AC 27 ms 1076 KB
01_rnd_06.txt AC 24 ms 920 KB
01_rnd_07.txt AC 38 ms 2548 KB
01_rnd_08.txt AC 83 ms 2804 KB
01_rnd_09.txt AC 111 ms 2544 KB
01_rnd_10.txt AC 103 ms 2672 KB
01_rnd_11.txt AC 69 ms 1784 KB
01_rnd_12.txt AC 51 ms 1660 KB
01_rnd_13.txt AC 26 ms 924 KB
01_rnd_14.txt AC 70 ms 2172 KB
01_rnd_15.txt AC 45 ms 1668 KB
01_rnd_16.txt AC 33 ms 1432 KB
01_rnd_17.txt AC 36 ms 1908 KB
01_rnd_18.txt AC 22 ms 784 KB
01_rnd_19.txt AC 23 ms 912 KB
01_rnd_20.txt AC 22 ms 1008 KB
02_maxrnd_01.txt AC 131 ms 3064 KB
02_maxrnd_02.txt AC 134 ms 3068 KB
02_maxrnd_03.txt AC 144 ms 3068 KB
02_maxrnd_04.txt AC 137 ms 3068 KB
02_maxrnd_05.txt AC 149 ms 2948 KB
02_maxrnd_06.txt AC 146 ms 3064 KB
02_maxrnd_07.txt AC 144 ms 3068 KB
02_maxrnd_08.txt AC 149 ms 3060 KB
02_maxrnd_09.txt AC 149 ms 2940 KB
02_maxrnd_10.txt AC 150 ms 3068 KB
02_maxrnd_11.txt AC 146 ms 3068 KB
02_maxrnd_12.txt AC 135 ms 3068 KB
02_maxrnd_13.txt AC 128 ms 3080 KB
02_maxrnd_14.txt AC 107 ms 3060 KB
02_maxrnd_15.txt AC 86 ms 3020 KB
02_maxrnd_16.txt AC 69 ms 2944 KB
02_maxrnd_17.txt AC 59 ms 2940 KB
02_maxrnd_18.txt AC 35 ms 1404 KB
02_maxrnd_19.txt AC 33 ms 1268 KB
03_hard_01.txt AC 77 ms 2944 KB
03_hard_02.txt AC 79 ms 2940 KB
03_hard_03.txt WA 53 ms 2556 KB
03_hard_04.txt WA 55 ms 2940 KB
03_hard_05.txt AC 75 ms 2944 KB
03_hard_06.txt AC 76 ms 2948 KB
03_hard_07.txt WA 54 ms 2532 KB
03_hard_08.txt WA 55 ms 2944 KB
04_open_01.txt AC 62 ms 2932 KB
04_open_02.txt AC 125 ms 2944 KB
05_minihard_01.txt AC 22 ms 896 KB
05_minihard_02.txt AC 22 ms 924 KB
05_minihard_03.txt AC 22 ms 920 KB
05_minihard_04.txt AC 22 ms 888 KB
05_minihard_05.txt AC 21 ms 940 KB
05_minihard_06.txt AC 22 ms 920 KB
05_minihard_07.txt AC 21 ms 928 KB
05_minihard_08.txt AC 21 ms 920 KB