結果

問題 No.2456 Stamp Art
ユーザー hiro71687khiro71687k
提出日時 2023-09-04 00:40:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,574 bytes
コンパイル時間 4,343 ms
コンパイル使用メモリ 266,020 KB
実行使用メモリ 71,316 KB
最終ジャッジ日時 2023-09-04 00:40:19
合計ジャッジ時間 11,879 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 385 ms
39,256 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 287 ms
7,916 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 225 ms
7,620 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353;
ll inf=100990999999999909;
int main(){
    ll h,w;
    cin >> h >> w;
    vector<vector<char>>s(h+2,vector<char>(w+2,'.'));
    for (ll i = 0; i < h; i++)
    {
        for (ll j = 0; j < w; j++)
        {
            cin >> s[i+1][j+1];
        }
    }
    vector<vector<ll>>hh(h+2),ww(w+2);
    for (ll i = 1; i <=h; i++)
    {
        for (ll j = 0; j <=w+1; j++)
        {
            if (s[i][j]=='.')
            {
                hh[i].push_back(j);
            }
        }
    }
    for (ll i = 1; i <=w; i++)
    {
        for (ll j = 0; j <=h+1; j++)
        {
            if (s[j][i]=='.')
            {
                ww[i].push_back(j);
            }
        }
    }
    ll ans=inf;
    for (ll i = 1; i <=h; i++)
    {
        for (ll j = 1; j <=w; j++)
        {
            if (s[i][j]=='#')
            {
                ll v=lower_bound(hh[i].begin(),hh[i].end(),j)-hh[i].begin();
                ans=min(ans,hh[i][v]-hh[i][v-1]-1);
                v=lower_bound(ww[j].begin(),ww[j].end(),i)-ww[j].begin();
                ans=min(ans,ww[j][v]-ww[j][v-1]-1);
                if (s[i+1][j+1]!='#'&&s[i-1][j-1]!='#')
                {
                    ans=min(ans,1LL);
                }
                if (s[i-1][j+1]!='#'&&s[i+1][j-1]!='#')
                {
                    ans=min(ans,1LL);
                }
            }
        }
    }
    cout << ans << endl;
}
0