제출 #74078

#제출 시각아이디문제언어결과실행 시간메모리
74078funcsrMecho (IOI09_mecho)C++17
95 / 100
307 ms36692 KiB
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 const int DX[4]={-1,0,1,0}; const int DY[4]={0,-1,0,1}; int N, S; char A[800][800]; int T[800][800]; int dp[800][800]; bool f(int X) { queue<P> q; rep(x,N)rep(y,N)dp[x][y]=INF; rep(y,N)rep(x,N)if(A[x][y]=='M'&&1LL*X*S<T[x][y])dp[x][y]=X*S,q.push(P(x,y)); while(!q.empty()){ int x=q.front()._1, y=q.front()._2;q.pop(); rep(k,4){ int nx=x+DX[k],ny=y+DY[k]; if(nx<0||nx>=N||ny<0||ny>=N||A[nx][ny]=='T'||dp[nx][ny]<=dp[x][y]+1) continue; if (A[nx][ny]=='D')return true; if (dp[x][y]+1>=T[nx][ny]) continue; dp[nx][ny]=dp[x][y]+1; q.push(P(nx,ny)); } } return false; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> S; rep(y,N)rep(x,N)cin>>A[x][y],T[x][y]=INF; queue<P> q; rep(x,N)rep(y,N)if(A[x][y]=='H') T[x][y]=0, q.push(P(x,y)); while(!q.empty()){ int x=q.front()._1, y=q.front()._2;q.pop(); rep(k,4){ int nx=x+DX[k],ny=y+DY[k]; if(nx<0||nx>=N||ny<0||ny>=N||A[nx][ny]=='T'||T[nx][ny]!=INF) continue; T[nx][ny]=T[x][y]+S; q.push(P(nx,ny)); } } int lo=-1, hi=N*N+1; while (hi-lo>1){ int mid=(lo+hi)/2; if (f(mid)) lo = mid; else hi=mid; } cout << lo << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...