結果

問題 No.2509 Beam Shateki
ユーザー FplusFplusFFplusFplusF
提出日時 2023-10-20 21:40:19
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,332 ms / 2,000 ms
コード長 1,984 bytes
コンパイル時間 2,582 ms
コンパイル使用メモリ 215,536 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-20 17:48:55
合計ジャッジ時間 37,927 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll h,w;
    cin >> h >> w;
    vector<vector<ll>> a(h+2,vector<ll>(w+2,0));
    for(ll i=1;i<=h;i++){
        for(ll j=1;j<=w;j++){
            cin >> a[i][j];
        }
    }
    vector<pll> v;
    rep(i,h+2){
        rep(j,w+2){
            if(i==0||j==0||i==h+1||j==w+1) v.emplace_back(i,j);
        }
    }
    ll ans=0;
    for(auto [ai,aj]:v){
        for(ll di=-1;di<=1;di++){
            for(ll dj=-1;dj<=1;dj++){
                if(di==0&&dj==0) continue;
                ll now=0;
                set<pll> st;
                ll nai=ai,naj=aj;
                while(1<=nai+di&&nai+di<=h&&1<=naj+dj&&naj+dj<=w){
                    nai+=di;
                    naj+=dj;
                    st.insert({nai,naj});
                    now+=a[nai][naj];
                }
                for(auto [bi,bj]:v){
                    for(ll ei=-1;ei<=1;ei++){
                        for(ll ej=-1;ej<=1;ej++){
                            if(ei==0&&ej==0) continue;
                            ll nbi=bi,nbj=bj;
                            ll now2=now;
                            while(1<=nbi+ei&&nbi+ei<=h&&1<=nbj+ej&&nbj+ej<=w){
                                nbi+=ei;
                                nbj+=ej;
                                if(st.count({nbi,nbj})) continue;
                                now2+=a[nbi][nbj];
                            }
                            chmax(ans,now2);
                        }
                    }
                }
            }
        }
    }
    cout << ans << '\n';
}
0