結果

問題 No.2509 Beam Shateki
ユーザー PAKACHUPAKACHU
提出日時 2023-10-21 00:13:58
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,843 bytes
コンパイル時間 2,637 ms
コンパイル使用メモリ 159,912 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 00:14:05
合計ジャッジ時間 4,742 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 2 ms
4,348 KB
testcase_04 AC 3 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 3 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 5 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 5 ms
4,348 KB
testcase_24 AC 5 ms
4,348 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 5 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 4 ms
4,348 KB
testcase_44 AC 4 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 4 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 4 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 3 ms
4,348 KB
testcase_53 AC 1 ms
4,348 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 1 ms
4,348 KB
testcase_57 AC 2 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 WA -
testcase_62 AC 1 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const long long mod = 998244353;
const ll inf = 1LL << 60;
const int INF = 5e8;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }

    vector<int> row(h), col(w);
    vector<int> diag(h + w - 1), diag2(h + w - 1);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            row[i] += a[i][j];
            col[j] += a[i][j];
            diag[i + j] += a[i][j];
            diag2[i - j + w - 1] += a[i][j];
        }
    }

    auto check = [&](int a, int b, int c) {
        return b <= a and a <= c;
    };

    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ans = max(ans, row[i] + col[j] - a[i][j]);
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < h + w - 1; j++) {
            ans = max(ans, row[i] + diag[j] - ((check(j - i, 0, w - 1) ? a[i][j - i] : 0)));
        }
    }

    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h + w - 1; j++) {
            ans = max(ans, col[i] + diag[j] - ((check(j - i, 0, h - 1) ? a[j - i][i] : 0)));
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < h + w - 1; j++) {
            ans = max(ans, row[i] + diag2[j] - ((check(i - j + w - 1, 0, w - 1) ? a[i][i - j + w - 1] : 0)));
        }
    }

    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h + w - 1; j++) {
            ans = max(ans, col[i] + diag2[j] - ((check(i - j + w - 1, 0, h - 1) ? a[i - j + w - 1][i] : 0)));
        }
    }

    for (int i = 0; i < h + w - 1; i++) {
        for (int j = 0; j < h + w - 1; j++) {
            if ((i - j + w - 1) % 2) {
                ans = max(ans, diag[i] + diag2[j]);
            } else {
                ans = max(ans, diag[i] + diag2[j] - (((check((i - j + w - 1) / 2, 0, w - 1) and check((i + j - w + 1) / 2, 0, h - 1)) ? a[(i + j - w + 1) / 2][(i - j + w - 1) / 2] : 0)));
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = i + 1; j < h; j++)
            ans = max(ans, row[i] + row[j]);
    }

    for (int i = 0; i < w; i++) {
        for (int j = i + 1; j < w; j++)
            ans = max(ans, col[i] + col[j]);
    }

    for (int i = 0; i < h + w - 1; i++) {
        for (int j = i + 1; j < h + w - 1; j++)
            ans = max(ans, diag[i] + diag[j]);
    }

    for (int i = 0; i < h + w - 1; i++) {
        for (int j = i + 1; j < h + w - 1; j++)
            ans = max(ans, diag2[i] + diag2[j]);
    }

    cout << ans << endl;
}
0