結果

問題 No.2509 Beam Shateki
ユーザー ococonomy1ococonomy1
提出日時 2023-10-20 21:46:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,053 bytes
コンパイル時間 1,286 ms
コンパイル使用メモリ 118,044 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 21:46:45
合計ジャッジ時間 17,250 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 40 ms
4,348 KB
testcase_04 AC 44 ms
4,348 KB
testcase_05 AC 40 ms
4,348 KB
testcase_06 AC 40 ms
4,348 KB
testcase_07 AC 41 ms
4,348 KB
testcase_08 AC 37 ms
4,348 KB
testcase_09 AC 38 ms
4,348 KB
testcase_10 AC 38 ms
4,348 KB
testcase_11 AC 40 ms
4,348 KB
testcase_12 AC 39 ms
4,348 KB
testcase_13 AC 622 ms
4,348 KB
testcase_14 AC 602 ms
4,348 KB
testcase_15 AC 586 ms
4,348 KB
testcase_16 AC 589 ms
4,348 KB
testcase_17 AC 603 ms
4,348 KB
testcase_18 AC 593 ms
4,348 KB
testcase_19 AC 591 ms
4,348 KB
testcase_20 AC 617 ms
4,348 KB
testcase_21 AC 594 ms
4,348 KB
testcase_22 AC 614 ms
4,348 KB
testcase_23 AC 575 ms
4,348 KB
testcase_24 AC 610 ms
4,348 KB
testcase_25 AC 579 ms
4,348 KB
testcase_26 AC 592 ms
4,348 KB
testcase_27 AC 563 ms
4,348 KB
testcase_28 AC 605 ms
4,348 KB
testcase_29 AC 590 ms
4,348 KB
testcase_30 AC 602 ms
4,348 KB
testcase_31 AC 583 ms
4,348 KB
testcase_32 AC 596 ms
4,348 KB
testcase_33 AC 5 ms
4,348 KB
testcase_34 AC 87 ms
4,348 KB
testcase_35 AC 229 ms
4,348 KB
testcase_36 AC 31 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 21 ms
4,348 KB
testcase_39 AC 30 ms
4,348 KB
testcase_40 AC 109 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 49 ms
4,348 KB
testcase_43 AC 340 ms
4,348 KB
testcase_44 AC 398 ms
4,348 KB
testcase_45 AC 25 ms
4,348 KB
testcase_46 AC 71 ms
4,348 KB
testcase_47 AC 378 ms
4,348 KB
testcase_48 AC 59 ms
4,348 KB
testcase_49 AC 167 ms
4,348 KB
testcase_50 AC 181 ms
4,348 KB
testcase_51 AC 4 ms
4,348 KB
testcase_52 AC 111 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 1 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 1 ms
4,348 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 WA -
testcase_63 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using lg = long long;
using pii = pair<int, int>;
using pll = pair<lg, lg>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
// #define AMARI 1000000007
#define TEMOTO ((sizeof(long double) == 16) ? false : true)
#define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000)
#define el '\n'
#define El '\n'

#define MULTI_TEST_CASE false
void solve(void) {
    int h,w;
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w));
    vector<int> hsum(h,0),wsum(w,0);
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
            hsum[i] += a[i][j];
            wsum[j] += a[i][j];
            ans = max(ans,hsum[i]);
            ans = max(ans,wsum[j]);
        }
    }
    
    for(int i = 0; i < h; i++){
        for(int j = i + 1; j < h; j++){
            ans = max(ans,hsum[i] + hsum[j]);
        }
    }

    for(int i = 0; i < w; i++){
        for(int j = i + 1; j < w; j++){
            ans = max(ans,wsum[i] + wsum[j]);
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            ans = max(ans,hsum[i] + wsum[j] - a[i][j]);
        }
    }
    //i+jが一定(k)
    for(int k = 0; k < h + w; k++){
        int temp = 0;
        for(int i = 0; i < h + w; i++){
            if(i < h && k - i >= 0 && k - i < w)temp += a[i][k - i];
        }
        for(int i = 0; i < h; i++){
            int t2 = temp + hsum[i];
            int j = k - i;
            if(j >= 0 && j < w)t2 -= a[i][j];
            ans = max(ans,t2);
        }
        for(int j = 0; j < w; j++){
            int t2 = temp + wsum[j];
            int i = k - j;
            if(i >= 0 && i < h)t2 -= a[i][j];
            ans = max(ans,t2);
        }
    }

    //i-jが一定(k)
    for(int k = -1 * w; k < h; k++){
        int temp = 0;
        for(int i = 0; i < h + w; i++){
            if(i < h && i - k >= 0 && i - k < w)temp += a[i][i - k];
        }
        for(int i = 0; i < h; i++){
            int t2 = temp + hsum[i];
            int j = i - k;
            if(j >= 0 && j < w)t2 -= a[i][j];
            ans = max(ans,t2);
        }
        for(int j = 0; j < w; j++){
            int t2 = temp + wsum[j];
            int i = k + j;
            if(i >= 0 && i < h)t2 -= a[i][j];
            ans = max(ans,t2);
        }
    }

    //i+jが一定(k,l)
    for(int k = 0; k < h + w; k++){
        for(int l = 0; l < h + w; l++){
            int temp = 0;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(i + j == k || i + j == w)temp += a[i][j];
                }
            }
            ans = max(ans,temp);
        }
    }
    //i-jが一定
    for(int k = -1 * w; k < h; k++){
        for(int l = k + 1; l < w; l++){
            int temp = 0;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(i - j == k || i - j == l)temp += a[i][j];
                }
            }
            ans = max(ans,temp);
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int temp = 0;
            for(int k = 0; k < h; k++){
                for(int l = 0; l < w; l++){
                    if(i + j == k + l || i - j == k - l)temp += a[k][l];
                }
            }
            //if(i == 0 && j == 0)cerr << temp << el;
            ans = max(ans,temp);
        }
    }
    cout << ans << el;
    return;
}

void calc(void) {
    return;
}

signed main(void) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE) cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
0