結果

問題 No.2509 Beam Shateki
ユーザー umezoumezo
提出日時 2023-10-20 23:51:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,344 bytes
コンパイル時間 2,732 ms
コンパイル使用メモリ 209,924 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 23:52:22
合計ジャッジ時間 4,492 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 WA -
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 WA -
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 3 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 WA -
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

int A[110][110];
int H[110],W[110],RD[220],LD[220];
vector<int> HH(110),WW(110),RDD(220),LDD(220);
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w;
  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) cin>>A[i][j];
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      H[i]+=A[i][j];
      W[j]+=A[i][j];
      RD[i-j+w-1]+=A[i][j];
      LD[i+j-2]+=A[i][j];
      HH[i]+=A[i][j];
      WW[j]+=A[i][j];
      RDD[i-j+w-1]+=A[i][j];
      LDD[i+j-2]+=A[i][j];
    }
  }
  sort(ALL(HH)),sort(ALL(WW)),sort(ALL(RDD)),sort(ALL(LDD));
  reverse(ALL(HH)),reverse(ALL(WW)),reverse(ALL(RDD)),reverse(ALL(LDD));
  
  int ans=0;
  if(h>1) ans=max(ans,HH[0]+HH[1]);
  else ans=max(ans,HH[0]);
  
  if(w>1) ans=max(ans,WW[0]+WW[1]);
  else ans=max(ans,WW[0]);
  
  if(h+w>2)  ans=max(ans,RDD[0]+RDD[1]);
  else ans=max(ans,RDD[0]);
  
  if(h+w>2)  ans=max(ans,LDD[0]+LDD[1]);
  else ans=max(ans,LDD[0]);
  
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      ans=max(ans,H[i]+W[j]-A[i][j]);
    }
  }
  for(int j=1;j<=w;j++){
    for(int k=0;k<=h+w-2;k++){
      int ni=j-w+1+k;
      if(1<=ni && ni<=h) ans=max(ans,W[j]+RD[k]-A[ni][j]);
      else ans=max(ans,W[j]+RD[k]);
    }
    for(int k=0;k<=h+w-2;k++){
      int ni=-j+2+k;
      if(1<=ni && ni<=h) ans=max(ans,W[j]+LD[k]-A[ni][j]);
      else ans=max(ans,W[j]+LD[k]);
    }
  }
  for(int i=1;i<=h;i++){
    for(int k=0;k<=h+w-2;k++){
      int nj=i+w-1-k;
      if(1<=nj && nj<=w) ans=max(ans,H[i]+RD[k]-A[i][nj]);
      else ans=max(ans,H[i]+RD[k]);
    }
    for(int k=0;k<=h+w-2;k++){
      int nj=i+w-1-k;
      if(1<=nj && nj<=w) ans=max(ans,H[i]+LD[k]-A[i][nj]);
      else ans=max(ans,H[i]+LD[k]);
    }
  }
  for(int k=0;k<=h+w-2;k++){
    for(int l=0;l<=h+w-2;l++){
      int dh=k+l-w+3,dw=w+1+l-k;
      if(dh%2==0 && dw%2==0 && 1<=dh/2 && dh/2<=h && dw/2>=1 && dw/2<=w){
        ans=max(ans,RD[k]+LD[l]-A[dh/2][dw/2]);
      }
      else ans=max(ans,RD[k]+LD[l]);
    }
  }
  for(int i=1;i<=h;i++) ans=max(ans,H[i]);
  for(int j=1;j<=w;j++) ans=max(ans,W[j]);
  for(int k=0;k<=h+w-2;k++){
    ans=max(ans,RD[k]);
    ans=max(ans,LD[k]);
  }
  cout<<ans<<endl;
    
  return 0;
}
0