Submission #18933


Source Code Expand

Copy
// compile with "g++ XXX.cc -mno-cygwin -O2" in Cygwin

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>
#include<bitset>
#include<cassert>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define FOR3(i,a,b) for(int i=a,i##_end=b;i<i##_end;i++)
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define CLS(x,val) memset((x) , val , sizeof(x)) 
typedef long long ll_t;
typedef long double ld_t;
typedef vector<int> VI; 
typedef vector<VI> VVI;
typedef complex<int> xy_t;

template<typename T> void debug(T v , string delimiter = "\n")
{ for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++) cout << *it << delimiter; cout << flush ;}

int dx[]  = {0,1,0,-1};
int dy[]  = {1,0,-1,0};
string ds = "SENW";

const double PI = 4.0*atan(1.0);

struct data{
  int row,col;
  int step;
};

bool visited[555][555];
long double pw[30000];

int main() {
  pw[0]=1.0;
  FOR(i,30000)if(i){
    pw[i] = pw[i-1] * 0.99;
  }

  int N,M;
  cin>>N>>M;
  vector<string> dat(N);

  FOR(i,N) cin>>dat[i];
  long double lower = 0 , upper = 100;
  int srow , scol , grow , gcol;
  FOR(i,N) FOR(j,M){
    if(dat[i][j]=='s') { srow = i ; scol = j; }
    if(dat[i][j]=='g') { grow = i ; gcol = j; }
  }
  bool kaiari = false;
  FOR(_,120){
    bool last = (_==119);
    long double p = (lower + upper) / 2.0;
    queue<data> qu;
    qu.push((data){srow , scol , 0});
    memset(visited , 0 , sizeof(visited));
    bool ok = false;
    while(!qu.empty()){
      data now = qu.front() ;qu.pop();
      char c = dat[now.row][now.col];
      if(c != 's' && c != 'g' && last==false){
        assert(isdigit(c));
        long double hiatari = (c - '0') * pw[now.step];
        if(hiatari < p) continue;
      }
      if(c == 'g'){
        kaiari = true;
        ok = true; break;
      }
      if(visited[now.row][now.col]) continue;
      visited[now.row][now.col] = true;
      FOR(k,4){
        int nrow = now.row + dy[k];
        int ncol = now.col + dx[k];
        if(BET(0,nrow,N) && BET(0,ncol,M) && dat[nrow][ncol] != '#'){
          qu.push((data){nrow , ncol, now.step+1});
        }
      }
    }
    if(ok) lower = p ;
    else upper = p;
  }
  if(kaiari){
    printf("%.20f\n", (double)lower);
  }else{
    puts("-1");
  }
  return 0 ;
}

Submission Info

Submission Time
Task C - 暗闇帰り道
User EmK
Language C++ (G++ 4.6.4)
Score 100
Code Size 2769 Byte
Status AC
Exec Time 2252 ms
Memory 1868 KB

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 64
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 27 ms 1560 KB
00_mini_02.txt AC 26 ms 1564 KB
00_mini_03.txt AC 26 ms 1560 KB
00_mini_04.txt AC 25 ms 1560 KB
00_mini_05.txt AC 26 ms 1556 KB
00_sample_01.txt AC 26 ms 1556 KB
00_sample_02.txt AC 25 ms 1556 KB
01_rnd_01.txt AC 1826 ms 1780 KB
01_rnd_02.txt AC 291 ms 1664 KB
01_rnd_03.txt AC 50 ms 1556 KB
01_rnd_04.txt AC 178 ms 1524 KB
01_rnd_05.txt AC 45 ms 1556 KB
01_rnd_06.txt AC 30 ms 1564 KB
01_rnd_07.txt AC 48 ms 1552 KB
01_rnd_08.txt AC 394 ms 1656 KB
01_rnd_09.txt AC 586 ms 1784 KB
01_rnd_10.txt AC 801 ms 1780 KB
01_rnd_11.txt AC 427 ms 1660 KB
01_rnd_12.txt AC 264 ms 1656 KB
01_rnd_13.txt AC 83 ms 1552 KB
01_rnd_14.txt AC 1111 ms 1680 KB
01_rnd_15.txt AC 470 ms 1668 KB
01_rnd_16.txt AC 32 ms 1540 KB
01_rnd_17.txt AC 480 ms 1692 KB
01_rnd_18.txt AC 27 ms 1520 KB
01_rnd_19.txt AC 29 ms 1540 KB
01_rnd_20.txt AC 28 ms 1584 KB
02_maxrnd_01.txt AC 543 ms 1784 KB
02_maxrnd_02.txt AC 397 ms 1784 KB
02_maxrnd_03.txt AC 630 ms 1784 KB
02_maxrnd_04.txt AC 1149 ms 1784 KB
02_maxrnd_05.txt AC 632 ms 1792 KB
02_maxrnd_06.txt AC 2239 ms 1756 KB
02_maxrnd_07.txt AC 201 ms 1792 KB
02_maxrnd_08.txt AC 106 ms 1788 KB
02_maxrnd_09.txt AC 2252 ms 1784 KB
02_maxrnd_10.txt AC 329 ms 1788 KB
02_maxrnd_11.txt AC 2039 ms 1788 KB
02_maxrnd_12.txt AC 930 ms 1792 KB
02_maxrnd_13.txt AC 1253 ms 1792 KB
02_maxrnd_14.txt AC 1462 ms 1780 KB
02_maxrnd_15.txt AC 230 ms 1788 KB
02_maxrnd_16.txt AC 1095 ms 1788 KB
02_maxrnd_17.txt AC 925 ms 1792 KB
02_maxrnd_18.txt AC 76 ms 1788 KB
02_maxrnd_19.txt AC 59 ms 1788 KB
03_hard_01.txt AC 2036 ms 1780 KB
03_hard_02.txt AC 2154 ms 1868 KB
03_hard_03.txt AC 68 ms 1760 KB
03_hard_04.txt AC 95 ms 1836 KB
03_hard_05.txt AC 2146 ms 1788 KB
03_hard_06.txt AC 2140 ms 1784 KB
03_hard_07.txt AC 67 ms 1788 KB
03_hard_08.txt AC 79 ms 1792 KB
04_open_01.txt AC 2161 ms 1788 KB
04_open_02.txt AC 2188 ms 1788 KB
05_minihard_01.txt AC 31 ms 1532 KB
05_minihard_02.txt AC 32 ms 1560 KB
05_minihard_03.txt AC 30 ms 1560 KB
05_minihard_04.txt AC 30 ms 1532 KB
05_minihard_05.txt AC 31 ms 1532 KB
05_minihard_06.txt AC 33 ms 1536 KB
05_minihard_07.txt AC 30 ms 1560 KB
05_minihard_08.txt AC 30 ms 1564 KB