結果

問題 No.2509 Beam Shateki
ユーザー PAKACHUPAKACHU
提出日時 2023-10-21 00:13:58
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,843 bytes
コンパイル時間 5,829 ms
コンパイル使用メモリ 163,784 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-21 00:44:00
合計ジャッジ時間 4,521 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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