結果

問題 No.2509 Beam Shateki
ユーザー FplusFplusF
提出日時 2023-10-20 21:34:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,024 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 208,056 KB
最終ジャッジ日時 2025-02-17 08:40:10
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 50
権限があれば一括ダウンロードができます

ソースコード

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(auto [bi,bj]: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(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