結果

問題 No.2509 Beam Shateki
ユーザー cho435
提出日時 2023-10-21 11:43:15
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 853 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 3,151 ms
コンパイル使用メモリ 103,192 KB
最終ジャッジ日時 2025-02-17 12:24:19
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<array>
#include<set>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h,w;
	cin>>h>>w;
	array<array<int,100>,100> a;
	rep(i,h) rep(j,w) cin>>a[i][j];
	array<int,4> dx={-1,0,1,1};
	array<int,4> dy={1,1,1,0};
	auto isok=[&](int x,int y){
		return 0<=x&&x<h&&0<=y&&y<w;
	};
	ll ans=0;
	rep(ch1,h+w-1){
		int x1=0,y1=0;
		if(ch1>=h) y1=ch1-h+1;
		else x1=ch1;
		rep(lp,2){
			for(int ch2=ch1;ch2<h+w-1;ch2++){
				int x2=0,y2=0;
				if(ch2>=h) y2=ch2-h+1;
				else x2=ch2;
				rep(rp,2){
					rep(i,4){
						int cx1=x1,cy1=y1;
						set<int> stl;
						ll res=0;
						while(isok(cx1,cy1)){
							res+=a[cx1][cy1];
							stl.insert(cx1+cy1*h);
							cx1+=dx[i];
							cy1+=dy[i];
						}
						rep(j,4){
							ll g2=0;
							int cx2=x2,cy2=y2;
							while(isok(cx2,cy2)){
								if(!stl.count(cx2+cy2*h)){
									g2+=a[cx2][cy2];
								}
								cx2+=dx[j];
								cy2+=dy[j];
							}
							ans=max(ans,res+g2);
						}
					}
					if(x2!=0) break;
					x2=h-1;
				}
			}
			if(x1!=0) break;
			x1=h-1;
		}
	}
	cout<<ans<<"\n";
}
0