結果
| 問題 | No.402 最も海から遠い場所 |
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2016-10-23 19:20:10 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 312 ms / 3,000 ms |
| コード長 | 1,598 bytes |
| 記録 | |
| コンパイル時間 | 1,225 ms |
| コンパイル使用メモリ | 185,496 KB |
| 実行使用メモリ | 122,388 KB |
| 最終ジャッジ日時 | 2026-05-17 22:34:02 |
| 合計ジャッジ時間 | 4,453 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:76:11: warning: 'res' may be used uninitialized [-Wmaybe-uninitialized]
76 | printf("%d\n", res);
| ~~~~~~^~~~~~~~~~~~~
main.cpp:55:9: note: 'res' was declared here
55 | int res;
| ^~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
using ll = long long;
using P = std::tuple<int,int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
string ma[3000];
int dist[3002][3002];
stack<P> st, st2;
int main(){
//*
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
/*/
/*/
int H, W;
std::cin >> H >> W;
memset(dist, -1, sizeof(dist));
for(int i=0;i<=H+1;++i){
dist[i][0] = 0;
dist[i][W+1] = 0;
st.emplace(i, 0);
st.emplace(i, W+1);
}
for(int i=0;i<=W+1;++i){
dist[0][i] = 0;
dist[H+1][i] = 0;
st.emplace(0, i);
st.emplace(H+1, i);
}
for(int i=0;i<H;++i){
std::cin >> ma[i];
for(int j=0;j<W;++j){
if(ma[i][j] == '.'){
dist[i+1][j+1] = 0;
st.emplace(i+1, j+1);
}
}
}
int res;
while(!st.empty()){
while(!st.empty()){
int y, x;
tie(y, x) = st.top(); st.pop();
for(int i=0;i<8;++i){
int ny = y + dy[i], nx = x + dx[i];
if(1 <= nx && nx <= W &&
1 <= ny && ny <= H &&
dist[ny][nx] == -1){
dist[ny][nx] = dist[y][x] + 1;
res = dist[ny][nx];
st2.emplace(ny, nx);
}
}
}
swap(st, st2);
}
printf("%d\n", res);
}
tottoripaper