Submission #18757


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];

int main() {
  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){
    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'){
        assert(isdigit(c));
        long double hiatari = (c - '0') * pow(0.99L , 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 0
Code Size 2638 Byte
Status WA
Exec Time 3877 ms
Memory 1400 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 27 ms 1020 KB
00_mini_02.txt AC 26 ms 1048 KB
00_mini_03.txt AC 26 ms 1020 KB
00_mini_04.txt AC 25 ms 1044 KB
00_mini_05.txt AC 24 ms 996 KB
00_sample_01.txt AC 25 ms 1048 KB
00_sample_02.txt AC 26 ms 1044 KB
01_rnd_01.txt AC 2999 ms 1276 KB
01_rnd_02.txt AC 403 ms 1144 KB
01_rnd_03.txt AC 57 ms 1020 KB
01_rnd_04.txt AC 235 ms 1168 KB
01_rnd_05.txt AC 52 ms 1048 KB
01_rnd_06.txt AC 31 ms 1020 KB
01_rnd_07.txt AC 56 ms 1156 KB
01_rnd_08.txt AC 517 ms 1144 KB
01_rnd_09.txt AC 779 ms 1280 KB
01_rnd_10.txt AC 1083 ms 1272 KB
01_rnd_11.txt AC 568 ms 1144 KB
01_rnd_12.txt AC 338 ms 1144 KB
01_rnd_13.txt AC 103 ms 1024 KB
01_rnd_14.txt AC 1476 ms 1248 KB
01_rnd_15.txt AC 600 ms 1140 KB
01_rnd_16.txt AC 31 ms 1152 KB
01_rnd_17.txt AC 656 ms 1148 KB
01_rnd_18.txt AC 25 ms 1048 KB
01_rnd_19.txt AC 27 ms 1140 KB
01_rnd_20.txt AC 27 ms 1056 KB
02_maxrnd_01.txt AC 805 ms 1276 KB
02_maxrnd_02.txt AC 560 ms 1272 KB
02_maxrnd_03.txt AC 899 ms 1268 KB
02_maxrnd_04.txt AC 1640 ms 1276 KB
02_maxrnd_05.txt AC 884 ms 1280 KB
02_maxrnd_06.txt AC 3318 ms 1272 KB
02_maxrnd_07.txt AC 258 ms 1272 KB
02_maxrnd_08.txt AC 127 ms 1276 KB
02_maxrnd_09.txt AC 3023 ms 1272 KB
02_maxrnd_10.txt AC 420 ms 1268 KB
02_maxrnd_11.txt AC 2671 ms 1272 KB
02_maxrnd_12.txt AC 1775 ms 1348 KB
02_maxrnd_13.txt AC 1613 ms 1260 KB
02_maxrnd_14.txt AC 1902 ms 1376 KB
02_maxrnd_15.txt AC 289 ms 1276 KB
02_maxrnd_16.txt AC 1445 ms 1280 KB
02_maxrnd_17.txt AC 1286 ms 1276 KB
02_maxrnd_18.txt AC 90 ms 1276 KB
02_maxrnd_19.txt AC 65 ms 1272 KB
03_hard_01.txt AC 3625 ms 1288 KB
03_hard_02.txt AC 3826 ms 1276 KB
03_hard_03.txt WA 126 ms 1248 KB
03_hard_04.txt WA 152 ms 1280 KB
03_hard_05.txt AC 3687 ms 1400 KB
03_hard_06.txt AC 3813 ms 1400 KB
03_hard_07.txt WA 127 ms 1276 KB
03_hard_08.txt WA 150 ms 1276 KB
04_open_01.txt AC 3877 ms 1400 KB
04_open_02.txt AC 3841 ms 1376 KB
05_minihard_01.txt AC 37 ms 1028 KB
05_minihard_02.txt AC 37 ms 1052 KB
05_minihard_03.txt AC 34 ms 1048 KB
05_minihard_04.txt AC 33 ms 1080 KB
05_minihard_05.txt AC 35 ms 1044 KB
05_minihard_06.txt AC 37 ms 1044 KB
05_minihard_07.txt AC 34 ms 1048 KB
05_minihard_08.txt AC 35 ms 1044 KB