結果

問題 No.2509 Beam Shateki
ユーザー hiro71687khiro71687k
提出日時 2023-10-20 21:53:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,305 ms / 2,000 ms
コード長 3,275 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 207,776 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 21:55:05
合計ジャッジ時間 37,719 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 174 ms
4,348 KB
testcase_04 AC 175 ms
4,348 KB
testcase_05 AC 174 ms
4,348 KB
testcase_06 AC 174 ms
4,348 KB
testcase_07 AC 174 ms
4,348 KB
testcase_08 AC 173 ms
4,348 KB
testcase_09 AC 174 ms
4,348 KB
testcase_10 AC 174 ms
4,348 KB
testcase_11 AC 176 ms
4,348 KB
testcase_12 AC 173 ms
4,348 KB
testcase_13 AC 1,242 ms
4,348 KB
testcase_14 AC 1,266 ms
4,348 KB
testcase_15 AC 1,270 ms
4,348 KB
testcase_16 AC 1,244 ms
4,348 KB
testcase_17 AC 1,263 ms
4,348 KB
testcase_18 AC 1,268 ms
4,348 KB
testcase_19 AC 1,236 ms
4,348 KB
testcase_20 AC 1,243 ms
4,348 KB
testcase_21 AC 1,262 ms
4,348 KB
testcase_22 AC 1,262 ms
4,348 KB
testcase_23 AC 1,246 ms
4,348 KB
testcase_24 AC 1,305 ms
4,348 KB
testcase_25 AC 1,268 ms
4,348 KB
testcase_26 AC 1,268 ms
4,348 KB
testcase_27 AC 1,263 ms
4,348 KB
testcase_28 AC 1,240 ms
4,348 KB
testcase_29 AC 1,264 ms
4,348 KB
testcase_30 AC 1,263 ms
4,348 KB
testcase_31 AC 1,256 ms
4,348 KB
testcase_32 AC 1,272 ms
4,348 KB
testcase_33 AC 30 ms
4,348 KB
testcase_34 AC 304 ms
4,348 KB
testcase_35 AC 631 ms
4,348 KB
testcase_36 AC 123 ms
4,348 KB
testcase_37 AC 15 ms
4,348 KB
testcase_38 AC 136 ms
4,348 KB
testcase_39 AC 117 ms
4,348 KB
testcase_40 AC 380 ms
4,348 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 162 ms
4,348 KB
testcase_43 AC 769 ms
4,348 KB
testcase_44 AC 913 ms
4,348 KB
testcase_45 AC 114 ms
4,348 KB
testcase_46 AC 203 ms
4,348 KB
testcase_47 AC 904 ms
4,348 KB
testcase_48 AC 256 ms
4,348 KB
testcase_49 AC 446 ms
4,348 KB
testcase_50 AC 508 ms
4,348 KB
testcase_51 AC 27 ms
4,348 KB
testcase_52 AC 352 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 3 ms
4,348 KB
testcase_55 AC 3 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 3 ms
4,348 KB
testcase_59 AC 3 ms
4,348 KB
testcase_60 AC 3 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 <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;
}
0