結果

問題 No.2509 Beam Shateki
ユーザー ococonomy1ococonomy1
提出日時 2023-10-20 21:32:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,884 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 115,928 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 21:32:57
合計ジャッジ時間 2,716 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 3 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 WA -
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 2 ms
4,348 KB
testcase_59 AC 1 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 1 ms
4,348 KB
testcase_62 WA -
testcase_63 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
    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];
        }
    }
    
    int ans = 0;
    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);
        }
    }
    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