SRM301 D1M EscapingJail

TopCoder Statistics - Problem Statement

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

隣接行列が与えられるので,全ての二点間の最短経路の中の最長を出す.$N \leq 50$なので,warshall_floydした.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<28
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n;
int cost[55][55];

int f(char c) {
  if('0' <= c && c <= '9') return (c - '0');
  if('a' <= c && c <= 'z') return (c - 'a' + 10);
  if('A' <= c && c <= 'Z') return (c - 'A' + 36);
  return INF;
}

class EscapingJail {
  public:
  int getMaxDistance(vector<string> v) {
      int n = v.size();
      memset(cost, 0, sizeof(cost));

      rep(i, n) {
          rep(j, n) {
              cost[i][j] = f(v[i][j]);
          }
      }

      rep(k, n) {
          rep(i, n) {
              rep(j, n) {
                  cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
              }
          }
      }

      int ans = -1;
      rep(i, n) {
          rep(j, n) {
              if(i == j) continue;
              if(cost[i][j] == INF) continue;
              ans = max(ans, cost[i][j]);
          }
      }

      return ans;
  }
};
Aug 21st, 2016