結果

問題 No.2509 Beam Shateki
ユーザー otoshigootoshigo
提出日時 2023-10-20 22:01:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,631 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 99,920 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 22:02:06
合計ジャッジ時間 56,404 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 272 ms
4,348 KB
testcase_04 AC 281 ms
4,348 KB
testcase_05 AC 265 ms
4,348 KB
testcase_06 AC 286 ms
4,348 KB
testcase_07 AC 266 ms
4,348 KB
testcase_08 AC 284 ms
4,348 KB
testcase_09 AC 277 ms
4,348 KB
testcase_10 AC 281 ms
4,348 KB
testcase_11 AC 271 ms
4,348 KB
testcase_12 AC 280 ms
4,348 KB
testcase_13 AC 1,959 ms
4,348 KB
testcase_14 TLE -
testcase_15 AC 1,978 ms
4,348 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 1,982 ms
4,348 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 1,988 ms
4,348 KB
testcase_22 TLE -
testcase_23 AC 1,999 ms
4,348 KB
testcase_24 AC 1,987 ms
4,348 KB
testcase_25 AC 1,997 ms
4,348 KB
testcase_26 AC 1,988 ms
4,348 KB
testcase_27 TLE -
testcase_28 AC 1,983 ms
4,348 KB
testcase_29 AC 1,979 ms
4,348 KB
testcase_30 AC 1,984 ms
4,348 KB
testcase_31 AC 1,982 ms
4,348 KB
testcase_32 TLE -
testcase_33 AC 47 ms
4,348 KB
testcase_34 AC 480 ms
4,348 KB
testcase_35 AC 1,014 ms
4,348 KB
testcase_36 AC 225 ms
4,348 KB
testcase_37 AC 108 ms
4,348 KB
testcase_38 AC 236 ms
4,348 KB
testcase_39 AC 233 ms
4,348 KB
testcase_40 AC 587 ms
4,348 KB
testcase_41 AC 8 ms
4,348 KB
testcase_42 AC 307 ms
4,348 KB
testcase_43 AC 1,211 ms
4,348 KB
testcase_44 AC 1,452 ms
4,348 KB
testcase_45 AC 205 ms
4,348 KB
testcase_46 AC 411 ms
4,348 KB
testcase_47 AC 1,378 ms
4,348 KB
testcase_48 AC 419 ms
4,348 KB
testcase_49 AC 706 ms
4,348 KB
testcase_50 AC 761 ms
4,348 KB
testcase_51 AC 48 ms
4,348 KB
testcase_52 AC 529 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 3 ms
4,348 KB
testcase_56 AC 3 ms
4,348 KB
testcase_57 AC 3 ms
4,348 KB
testcase_58 AC 3 ms
4,348 KB
testcase_59 AC 3 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 3 ms
4,348 KB
testcase_62 AC 3 ms
4,348 KB
testcase_63 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const int dx[]={-1,0,1},dy[]={-1,0,1};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin>>H>>W;
    vector A(H+2,vector<ll>(W+2));
    for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)cin>>A[i][j];
    vector<pair<int,int>>vp;
    for(int i=0;i<=W;i++)vp.push_back(make_pair(0,i));
    for(int i=0;i<=H;i++)vp.push_back(make_pair(i,W+1));
    for(int i=W+1;i>=1;i--)vp.push_back(make_pair(H+1,i));
    for(int i=H+1;i>=1;i--)vp.push_back(make_pair(i,0));
    int L=vp.size();
    vector D(L,vector(3,vector<ll>(3)));
    for(int i=0;i<L-1;i++){
        for(int k=0;k<3;k++)for(int l=0;l<3;l++){
            if(k==1&&l==1)continue;
            ll cnt=0;
            int axi=vp[i].first,ayi=vp[i].second;
            while(axi>=0&&axi<=H+1&&ayi>=0&&ayi<=W+1){
                cnt+=A[axi][ayi];
                axi+=dx[k];
                ayi+=dy[l];
            }
            D[i][k][l]=cnt;
        }
    }
    ll ans=0;
    vector flag(H+2,vector<bool>(W+1));
    for(int i=0;i<L-1;i++){
        for(int j=i+1;j<L;j++){
            for(int a=0;a<3;a++)for(int b=0;b<3;b++)for(int c=0;c<3;c++)for(int d=0;d<3;d++){
                if((a==1&&b==1)||(c==1&&d==1))continue;
                ll cnt=D[i][a][b]+D[j][c][d];
                int axi=vp[i].first,ayi=vp[i].second;
                int axj=vp[j].first,ayj=vp[j].second;
                set<pair<int,int>>se;
                while(axi>=0&&axi<=H+1&&ayi>=0&&ayi<=W+1){
                    flag[axi][ayi]=true;
                    axi+=dx[a];
                    ayi+=dy[b];
                }
                while(axj>=0&&axj<=H+1&&ayj>=0&&ayj<=W+1){
                    if(flag[axj][ayj]){
                        cnt-=A[axj][ayj];
                    }
                    axj+=dx[c];
                    ayj+=dy[d];
                }
                if(axi-dx[a]==vp[j].first&&ayi-dy[b]==vp[j].second)continue;
                chmax(ans,cnt);
                while(axi-dx[a]>=0&&axi-dx[a]<=H+1&&ayi-dy[b]>=0&&ayi-dy[b]<=W+1){
                    axi-=dx[a];
                    ayi-=dy[b];
                    flag[axi][ayi]=false;
                }
            }
        }
    }
    cout<<ans<<"\n";
}
0