結果
| 問題 |
No.2412 YOU Grow Bigger!
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2023-08-11 22:06:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 6,000 ms |
| コード長 | 1,521 bytes |
| コンパイル時間 | 1,939 ms |
| コンパイル使用メモリ | 181,916 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 08:43:22 |
| 合計ジャッジ時間 | 2,596 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
int main(){
int H, W;
cin >> H >> W;
vector<vector<char>> S(H + 2, vector<char>(W + 2, '#'));
for (int i = 1; i <= H; i++){
for (int j = 1; j <= W; j++){
cin >> S[i][j];
}
}
vector<vector<int>> d(H + 2, vector<int>(W + 2, -1));
deque<tuple<int, int, int>> dq;
for (int i = 4; i < H + 2; i++){
dq.push_back(make_tuple(0, i, 0));
}
for (int i = 1; i < W - 2; i++){
dq.push_back(make_tuple(0, H + 1, i));
}
while (!dq.empty()){
int c = get<0>(dq.front());
int x = get<1>(dq.front());
int y = get<2>(dq.front());
dq.pop_front();
if (d[x][y] == -1){
d[x][y] = c;
for (int i = -3; i <= 3; i++){
for (int j = -3; j <= 3; j++){
if (abs(i) + abs(j) < 6){
int x2 = x + i;
int y2 = y + j;
if (0 <= x2 && x2 < H + 2 && 0 <= y2 && y2 < W + 2){
if (d[x2][y2] == -1){
if (!(x2 < 4 && y2 < 4) && !(x2 >= H - 2 && y2 >= W - 2)){
if (S[x2][y2] == '#'){
dq.push_front(make_tuple(c, x2, y2));
} else {
dq.push_back(make_tuple(c + 1, x2, y2));
}
}
}
}
}
}
}
}
}
int ans = INF;
for (int i = 4; i < W + 2; i++){
ans = min(ans, d[0][i]);
}
for (int i = 1; i < H - 2; i++){
ans = min(ans, d[i][W + 1]);
}
cout << ans << endl;
}
SSRS