結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-03 09:24:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,417 bytes |
| コンパイル時間 | 1,469 ms |
| コンパイル使用メモリ | 160,372 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-09-30 23:40:19 |
| 合計ジャッジ時間 | 2,081 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int w, h;
char a[100][100];
int dx[]={1, 0, -1, 0};
int dy[]={0, 1, 0, -1};
int cnt = 1;
void dfs(int x, int y, int cnt) {
a[x][y] = '0' + cnt;
for (int i = 0; i < 4; i++) {
if (a[x+dx[i]][y+dy[i]] == '.') {
dfs(x+dx[i], y+dy[i], cnt);
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
freopen("input.txt", "r", stdin);
cin >> w >> h;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (a[i][j] == '.') {
dfs(i, j, cnt);
cnt = cnt + 1;
}
}
}
int ans = INT_MAX;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (a[i][j] == '1') {
for(int k = 0; k < h; k++) {
for (int m = 0; m < w; m++) {
if (a[k][m] == '2') {
ans = min(ans, abs(i-k) + abs(j-m));
}
}
}
}
}
}
cout << ans << endl;
// for (int i = 0; i < h; i++) {
// for (int j = 0; j < w; j++) {
// cout << a[i][j];
// }
// cout << "\n";
// }
return 0;
}