結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 44 ms
4,348 KB
testcase_04 AC 44 ms
4,348 KB
testcase_05 AC 44 ms
4,348 KB
testcase_06 AC 43 ms
4,348 KB
testcase_07 AC 44 ms
4,348 KB
testcase_08 AC 43 ms
4,348 KB
testcase_09 AC 44 ms
4,348 KB
testcase_10 AC 43 ms
4,348 KB
testcase_11 AC 43 ms
4,348 KB
testcase_12 AC 43 ms
4,348 KB
testcase_13 AC 678 ms
4,348 KB
testcase_14 AC 654 ms
4,348 KB
testcase_15 AC 656 ms
4,348 KB
testcase_16 AC 683 ms
4,348 KB
testcase_17 AC 656 ms
4,348 KB
testcase_18 AC 656 ms
4,348 KB
testcase_19 AC 673 ms
4,348 KB
testcase_20 AC 654 ms
4,348 KB
testcase_21 AC 704 ms
4,348 KB
testcase_22 AC 656 ms
4,348 KB
testcase_23 AC 658 ms
4,348 KB
testcase_24 AC 680 ms
4,348 KB
testcase_25 AC 657 ms
4,348 KB
testcase_26 AC 655 ms
4,348 KB
testcase_27 AC 678 ms
4,348 KB
testcase_28 AC 653 ms
4,348 KB
testcase_29 AC 653 ms
4,348 KB
testcase_30 AC 677 ms
4,348 KB
testcase_31 AC 657 ms
4,348 KB
testcase_32 AC 653 ms
4,348 KB
testcase_33 AC 4 ms
4,348 KB
testcase_34 AC 95 ms
4,348 KB
testcase_35 AC 264 ms
4,348 KB
testcase_36 AC 38 ms
4,348 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 31 ms
4,348 KB
testcase_39 AC 27 ms
4,348 KB
testcase_40 AC 122 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 43 ms
4,348 KB
testcase_43 AC 342 ms
4,348 KB
testcase_44 AC 432 ms
4,348 KB
testcase_45 AC 26 ms
4,348 KB
testcase_46 AC 60 ms
4,348 KB
testcase_47 AC 442 ms
4,348 KB
testcase_48 AC 73 ms
4,348 KB
testcase_49 AC 171 ms
4,348 KB
testcase_50 AC 199 ms
4,348 KB
testcase_51 AC 5 ms
4,348 KB
testcase_52 AC 110 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 3 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 2 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 < h; 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