結果
問題 |
No.2412 YOU Grow Bigger!
|
ユーザー |
![]() |
提出日時 | 2023-08-11 22:14:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,169 bytes |
コンパイル時間 | 3,645 ms |
コンパイル使用メモリ | 257,604 KB |
最終ジャッジ日時 | 2025-02-16 01:32:00 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 WA * 8 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int h,w; cin>>h>>w; vector<string> s(h); rep(i,h)cin>>s[i]; vector d(h,vector<int>(w,Inf32)); deque<pair<int,int>> D; for(int i=h-3;i<h;i++){ rep(j,w-3){ if(s[i][j]=='#'){ d[i][j] = 0; D.emplace_back(i,j); } else{ d[i][j] = 1; D.emplace_front(i,j); } } } while(D.size()>0){ int x = D.back().first,y = D.back().second; D.pop_back(); for(int i=-3;i<=3;i++){ for(int j=-3;j<=3;j++){ int xx = x+i,yy = y+j; if(xx<0||xx>=h||yy<0||yy>=w)continue; int cost = d[x][y]; if(s[xx][yy]=='.')cost++; if(xx<3&&yy<3)continue; if(xx>=h-3&&yy>=w-3)continue; if(d[xx][yy]<=cost)continue; d[xx][yy] = cost; if(s[xx][yy]=='.'){ D.emplace_front(xx,yy); } else D.emplace_back(xx,yy); } } } int ans = Inf32; rep(i,h){ for(int j=w-3;j<w;j++){ ans =min(ans,d[i][j]); } } cout<<ans<<endl; return 0; }