結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint1000000007;

int main(){
	int h,w;
	cin>>h>>w;
	vector<vector<ll>> a(h,vector<ll>(w));
	rep(i,h) rep(j,w) cin>>a.at(i).at(j);
	vector<int> dx={-1,0,1,1,1};
	vector<int> dy={1,1,1,0,-1};
	auto isok=[&](int x,int y){
		return 0<=x&&x<h&&0<=y&&y<w;
	};
	auto select=[&](int x1,int y1,int i,int x2,int y2,int j){
		set<int> stl;
		ll res=0;
		while(isok(x1,y1)){
			res+=a.at(x1).at(y1);
			stl.insert(x1+y1*h);
			x1+=dx.at(i);
			y1+=dy.at(i);
		}
		while(isok(x2,y2)){
			if(!stl.count(x2+y2*h)){
				res+=a.at(x2).at(y2);
			}
			x2+=dx.at(j);
			y2+=dy.at(j);
		}
		return res;
	};
	ll ans=0;
	rep(ch1,h+w-1){
		int x1=0,y1=0;
		if(ch1>=h) y1=ch1-h+1;
		else x1=ch1;
		rep(ch2,h+w-1){
			int x2=0,y2=0;
			if(ch2>=h) y2=ch2-h+1;
			else x2=ch2;
			rep(i,5){
				rep(j,5){
					ans=max(ans,select(x1,y1,i,x2,y2,j));
				}
			}
		}
	}
	cout<<ans<<endl;
}
0