Submission #19558


Source Code Expand

Copy
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

class C{
	struct Node{
		int next;
		int sec;
		Node(int n,int s):next(n),sec(s){}
	};
	int N,M;
	vector<string> field;
	bool isValid(int y,int x){
		return y>=0 && y<N && x>=0 && x<M;
	}
public:
	bool init(){
		if(scanf("%d%d",&N,&M)==EOF)return false;
		field.resize(N);
		REP(i,N){
			char buf[1024];
			scanf("%s",buf);
			field[i] = string(buf);
		}
		return true;
	}
	void solve(){
		int sy,sx,gy,gx;
		REP(y,N)REP(x,M){
			if(field[y][x]=='s'){
				sy = y;
				sx = x;
			}
			if(field[y][x]=='g'){
				gy = y;
				gx = x;
			}
		}
		vector<double> pre(4*N*M,1);
		REP(i,4*N*M-1)pre[i+1] = pre[i]*0.99;
		vector<vector<double> > used(N,vector<double>(M,-2));
		vector<vector<int> > inQue(N,vector<int>(M,0));
		queue<Node> que;que.push(Node(sy*M+sx,0));
		inQue[sy][sx] = 1;
		used[sy][sx] = 100;
		while(!que.empty()){
			Node n = que.front();que.pop();
			int cy = n.next/M;
			int cx = n.next%M;
			//cout << cy << "," << cx << " " << used[cy][cx] << endl;
			inQue[cy][cx] = 0;
			const int DY[] = {-1,0,1,0};
			const int DX[] = {0,1,0,-1};
			REP(i,4){
				int ny = cy+DY[i];
				int nx = cx+DX[i];
				
				if(!isValid(ny,nx) || field[ny][nx]=='#')continue;
				double cost = field[ny][nx]-'0';
				cost *= pre[n.sec+1];
				if(field[ny][nx]=='g')cost = 100;
				cost = min(used[cy][cx],cost);
				if(used[ny][nx]<cost){
					used[ny][nx] = cost;
					if(!inQue[ny][nx]){
						inQue[ny][nx] = 1;
						que.push(Node(ny*M+nx,n.sec+1));
					}
				}
			}
		}


		if(used[gy][gx]<-1)printf("-1\n");
		else printf("%.9f\n",(double)used[gy][gx]);
	}
};

int main(){
	C solver;
	while(solver.init()){
		solver.solve();
	}
	return 0;
}

Submission Info

Submission Time
Task C - 暗闇帰り道
User nel215
Language C++ (G++ 4.6.4)
Score 100
Code Size 2162 Byte
Status AC
Exec Time 219 ms
Memory 11860 KB

Compile Error

./Main.cpp: In member function ‘bool C::init()’:
./Main.cpp:41:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

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 21 ms 792 KB
00_mini_02.txt AC 21 ms 792 KB
00_mini_03.txt AC 21 ms 792 KB
00_mini_04.txt AC 21 ms 792 KB
00_mini_05.txt AC 21 ms 792 KB
00_sample_01.txt AC 21 ms 792 KB
00_sample_02.txt AC 21 ms 760 KB
01_rnd_01.txt AC 149 ms 9348 KB
01_rnd_02.txt AC 79 ms 4732 KB
01_rnd_03.txt AC 36 ms 1788 KB
01_rnd_04.txt AC 43 ms 2304 KB
01_rnd_05.txt AC 25 ms 1180 KB
01_rnd_06.txt AC 23 ms 924 KB
01_rnd_07.txt AC 36 ms 1788 KB
01_rnd_08.txt AC 106 ms 5760 KB
01_rnd_09.txt AC 151 ms 8188 KB
01_rnd_10.txt AC 135 ms 7168 KB
01_rnd_11.txt AC 93 ms 5120 KB
01_rnd_12.txt AC 66 ms 3716 KB
01_rnd_13.txt AC 25 ms 1272 KB
01_rnd_14.txt AC 110 ms 7032 KB
01_rnd_15.txt AC 71 ms 4856 KB
01_rnd_16.txt AC 47 ms 3320 KB
01_rnd_17.txt AC 60 ms 4732 KB
01_rnd_18.txt AC 22 ms 1280 KB
01_rnd_19.txt AC 33 ms 2676 KB
01_rnd_20.txt AC 22 ms 1428 KB
02_maxrnd_01.txt AC 187 ms 11768 KB
02_maxrnd_02.txt AC 196 ms 11764 KB
02_maxrnd_03.txt AC 200 ms 11768 KB
02_maxrnd_04.txt AC 200 ms 11776 KB
02_maxrnd_05.txt AC 208 ms 11772 KB
02_maxrnd_06.txt AC 207 ms 11776 KB
02_maxrnd_07.txt AC 210 ms 11780 KB
02_maxrnd_08.txt AC 219 ms 11772 KB
02_maxrnd_09.txt AC 217 ms 11772 KB
02_maxrnd_10.txt AC 218 ms 11772 KB
02_maxrnd_11.txt AC 217 ms 11860 KB
02_maxrnd_12.txt AC 207 ms 11776 KB
02_maxrnd_13.txt AC 199 ms 11768 KB
02_maxrnd_14.txt AC 188 ms 11780 KB
02_maxrnd_15.txt AC 169 ms 11768 KB
02_maxrnd_16.txt AC 153 ms 11788 KB
02_maxrnd_17.txt AC 138 ms 11764 KB
02_maxrnd_18.txt AC 119 ms 11776 KB
02_maxrnd_19.txt AC 119 ms 11776 KB
03_hard_01.txt AC 146 ms 11772 KB
03_hard_02.txt AC 143 ms 11768 KB
03_hard_03.txt AC 152 ms 11776 KB
03_hard_04.txt AC 152 ms 11768 KB
03_hard_05.txt AC 143 ms 11768 KB
03_hard_06.txt AC 143 ms 11780 KB
03_hard_07.txt AC 152 ms 11768 KB
03_hard_08.txt AC 151 ms 11780 KB
04_open_01.txt AC 145 ms 11772 KB
04_open_02.txt AC 180 ms 11764 KB
05_minihard_01.txt AC 22 ms 768 KB
05_minihard_02.txt AC 21 ms 792 KB
05_minihard_03.txt AC 22 ms 788 KB
05_minihard_04.txt AC 22 ms 784 KB
05_minihard_05.txt AC 21 ms 788 KB
05_minihard_06.txt AC 21 ms 812 KB
05_minihard_07.txt AC 21 ms 780 KB
05_minihard_08.txt AC 21 ms 788 KB