結果
| 問題 |
No.2509 Beam Shateki
|
| コンテスト | |
| ユーザー |
hiro71687k
|
| 提出日時 | 2023-10-20 21:53:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,212 ms / 2,000 ms |
| コード長 | 3,275 bytes |
| コンパイル時間 | 2,013 ms |
| コンパイル使用メモリ | 199,548 KB |
| 最終ジャッジ日時 | 2025-02-17 09:16:10 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 61 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353;
ll inf=10000000000000;//10^17
int main(){
ll h,w;
cin >> h >> w;
vector<vector<ll>>a(h+2,vector<ll>(w+2));
for (ll i = 0; i < h; i++)
{
for (ll j = 0; j < w; j++)
{
cin >> a[i+1][j+1];
}
}
ll now=0;
vector<vector<ll>>memo(h+2,vector<ll>(w+2,0));
ll x=0,y=0;
ll d=0;
ll ans=0;
while (1)
{
ll xx=0,yy=0;
ll dd=0;
while (1)
{
for (ll i = -1; i <=1; i++)
{
for (ll j = -1; j <=1; j++)
{
if (i==0&&j==0)
{
continue;
}
for (ll k = -1; k <=1; k++)
{
for (ll l = -1; l <=1; l++)
{
ll aa=0;
if (k==0&&l==0)
{
continue;
}
now++;
for (ll n = 1; n >=0; n++)
{
if (x+i*n<=0||x+i*n>=h+1||y+j*n<=0||y+j*n>=w+1)
{
break;
}
memo[x+i*n][y+j*n]=now;
aa+=a[x+i*n][y+j*n];
}
for (ll n = 1; n >=0; n++)
{
if (xx+k*n<=0||xx+k*n>=h+1||yy+l*n<=0||yy+l*n>=w+1)
{
break;
}
if (memo[xx+k*n][yy+l*n]!=now)
{
aa+=a[xx+k*n][yy+l*n];
}
}
ans=max(ans,aa);
now++;
}
}
}
}
if (dd==0)
{
yy++;
if (yy==w+1)
{
dd=1;
}
}else if (dd==1)
{
xx++;
if (xx==h+1)
{
dd=2;
}
}else if (dd==2)
{
yy--;
if (yy==0)
{
dd=3;
}
}else{
xx--;
if (xx==-1)
{
break;
}
}
}
if (d==0)
{
y++;
if (y==w+1)
{
d=1;
}
}else if (d==1)
{
x++;
if (x==h+1)
{
d=2;
}
}else if (d==2)
{
y--;
if (y==0)
{
d=3;
}
}else{
x--;
if (x==-1)
{
break;
}
}
}
cout << ans << endl;
}
hiro71687k