답안 #74079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74079 2018-08-30T03:31:42 Z funcsr Mecho (IOI09_mecho) C++17
100 / 100
335 ms 8152 KB
#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'||A[nx][ny]=='D'||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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 552 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 660 KB Output is correct
7 Correct 176 ms 6348 KB Output is correct
8 Correct 2 ms 6348 KB Output is correct
9 Correct 2 ms 6348 KB Output is correct
10 Correct 2 ms 6348 KB Output is correct
11 Correct 3 ms 6348 KB Output is correct
12 Correct 3 ms 6348 KB Output is correct
13 Correct 3 ms 6348 KB Output is correct
14 Correct 3 ms 6348 KB Output is correct
15 Correct 2 ms 6348 KB Output is correct
16 Correct 2 ms 6348 KB Output is correct
17 Correct 2 ms 6348 KB Output is correct
18 Correct 3 ms 6348 KB Output is correct
19 Correct 3 ms 6348 KB Output is correct
20 Correct 3 ms 6348 KB Output is correct
21 Correct 3 ms 6348 KB Output is correct
22 Correct 3 ms 6348 KB Output is correct
23 Correct 2 ms 6348 KB Output is correct
24 Correct 3 ms 6348 KB Output is correct
25 Correct 3 ms 6348 KB Output is correct
26 Correct 3 ms 6348 KB Output is correct
27 Correct 2 ms 6348 KB Output is correct
28 Correct 3 ms 6348 KB Output is correct
29 Correct 3 ms 6348 KB Output is correct
30 Correct 2 ms 6348 KB Output is correct
31 Correct 2 ms 6348 KB Output is correct
32 Correct 3 ms 6348 KB Output is correct
33 Correct 11 ms 6348 KB Output is correct
34 Correct 11 ms 6348 KB Output is correct
35 Correct 31 ms 6348 KB Output is correct
36 Correct 14 ms 6348 KB Output is correct
37 Correct 15 ms 6348 KB Output is correct
38 Correct 42 ms 6348 KB Output is correct
39 Correct 17 ms 6348 KB Output is correct
40 Correct 17 ms 6348 KB Output is correct
41 Correct 74 ms 6348 KB Output is correct
42 Correct 25 ms 6348 KB Output is correct
43 Correct 21 ms 6348 KB Output is correct
44 Correct 79 ms 6348 KB Output is correct
45 Correct 26 ms 6348 KB Output is correct
46 Correct 27 ms 6348 KB Output is correct
47 Correct 103 ms 6348 KB Output is correct
48 Correct 28 ms 6348 KB Output is correct
49 Correct 29 ms 6348 KB Output is correct
50 Correct 102 ms 6348 KB Output is correct
51 Correct 40 ms 6348 KB Output is correct
52 Correct 41 ms 6348 KB Output is correct
53 Correct 132 ms 6348 KB Output is correct
54 Correct 51 ms 6348 KB Output is correct
55 Correct 46 ms 6348 KB Output is correct
56 Correct 169 ms 6348 KB Output is correct
57 Correct 49 ms 6348 KB Output is correct
58 Correct 46 ms 6348 KB Output is correct
59 Correct 208 ms 6348 KB Output is correct
60 Correct 62 ms 6368 KB Output is correct
61 Correct 63 ms 6484 KB Output is correct
62 Correct 233 ms 6484 KB Output is correct
63 Correct 170 ms 6484 KB Output is correct
64 Correct 335 ms 6496 KB Output is correct
65 Correct 245 ms 6496 KB Output is correct
66 Correct 208 ms 6496 KB Output is correct
67 Correct 190 ms 6496 KB Output is correct
68 Correct 101 ms 6496 KB Output is correct
69 Correct 102 ms 6496 KB Output is correct
70 Correct 87 ms 6496 KB Output is correct
71 Correct 94 ms 6496 KB Output is correct
72 Correct 89 ms 6496 KB Output is correct
73 Correct 82 ms 6708 KB Output is correct
74 Correct 119 ms 6708 KB Output is correct
75 Correct 138 ms 6752 KB Output is correct
76 Correct 139 ms 6752 KB Output is correct
77 Correct 123 ms 6752 KB Output is correct
78 Correct 140 ms 6752 KB Output is correct
79 Correct 102 ms 6752 KB Output is correct
80 Correct 117 ms 6752 KB Output is correct
81 Correct 121 ms 6752 KB Output is correct
82 Correct 105 ms 6752 KB Output is correct
83 Correct 128 ms 6752 KB Output is correct
84 Correct 118 ms 6752 KB Output is correct
85 Correct 143 ms 6752 KB Output is correct
86 Correct 126 ms 6752 KB Output is correct
87 Correct 124 ms 7184 KB Output is correct
88 Correct 149 ms 7524 KB Output is correct
89 Correct 152 ms 7832 KB Output is correct
90 Correct 155 ms 8148 KB Output is correct
91 Correct 154 ms 8152 KB Output is correct
92 Correct 166 ms 8152 KB Output is correct