Submission #9458353
Source Code Expand
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int H, W;
string S[20];
//---------------------------------------------------------------------------------------------------
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
vector<vector<int>> bfs(int sx, int sy) {
queue<pair<int, int>> que;
vector<vector<int>> res(H, vector<int>(W, inf));
vector<vector<bool>> vis(H, vector<bool>(W, false));
res[sy][sx] = 0;
vis[sy][sx] = true;
que.push({ sx, sy });
while (!que.empty()) {
int x, y;
tie(x, y) = que.front();
que.pop();
rep(d, 0, 4) {
int xx = x + dx[d];
int yy = y + dy[d];
if (0 <= xx and xx < W and 0 <= yy and yy < H) {
if (S[yy][xx] != '#' and !vis[yy][xx]) {
res[yy][xx] = res[y][x] + 1;
vis[yy][xx] = true;
que.push({xx, yy});
}
}
}
}
return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> H >> W;
rep(y, 0, H) cin >> S[y];
int ans = 0;
rep(sx, 0, W) rep(sy, 0, H) if(S[sy][sx] != '#') {
auto res = bfs(sx, sy);
rep(x, 0, W) rep(y, 0, H) if (S[y][x] != '#') chmax(ans, res[y][x]);
}
cout << ans << endl;
}
Submission Info
| Submission Time |
|
| Task |
D - Maze Master |
| User |
hamayanhamayan |
| Language |
C++14 (GCC 5.4.1) |
| Score |
400 |
| Code Size |
2456 Byte |
| Status |
AC |
| Exec Time |
6 ms |
| Memory |
256 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01, sample_02 |
| All |
hand_01, hand_02, hand_03, hand_04, hand_05, hand_06, hand_07, hand_08, hand_09, hand_10, sample_01, sample_02, small_01, small_02, small_03, small_04 |
| Case Name |
Status |
Exec Time |
Memory |
| hand_01 |
AC |
3 ms |
256 KiB |
| hand_02 |
AC |
2 ms |
256 KiB |
| hand_03 |
AC |
2 ms |
256 KiB |
| hand_04 |
AC |
2 ms |
256 KiB |
| hand_05 |
AC |
4 ms |
256 KiB |
| hand_06 |
AC |
3 ms |
256 KiB |
| hand_07 |
AC |
2 ms |
256 KiB |
| hand_08 |
AC |
6 ms |
256 KiB |
| hand_09 |
AC |
1 ms |
256 KiB |
| hand_10 |
AC |
2 ms |
256 KiB |
| sample_01 |
AC |
1 ms |
256 KiB |
| sample_02 |
AC |
1 ms |
256 KiB |
| small_01 |
AC |
1 ms |
256 KiB |
| small_02 |
AC |
1 ms |
256 KiB |
| small_03 |
AC |
3 ms |
256 KiB |
| small_04 |
AC |
1 ms |
256 KiB |