結果

問題 No.2509 Beam Shateki
ユーザー 👑 emthrmemthrm
提出日時 2023-10-20 23:14:39
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 921 ms / 2,000 ms
コード長 2,234 bytes
コンパイル時間 4,125 ms
コンパイル使用メモリ 255,456 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 23:15:38
合計ジャッジ時間 29,919 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 126 ms
4,348 KB
testcase_04 AC 125 ms
4,348 KB
testcase_05 AC 125 ms
4,348 KB
testcase_06 AC 126 ms
4,348 KB
testcase_07 AC 126 ms
4,348 KB
testcase_08 AC 126 ms
4,348 KB
testcase_09 AC 126 ms
4,348 KB
testcase_10 AC 126 ms
4,348 KB
testcase_11 AC 126 ms
4,348 KB
testcase_12 AC 126 ms
4,348 KB
testcase_13 AC 919 ms
4,348 KB
testcase_14 AC 892 ms
4,348 KB
testcase_15 AC 894 ms
4,348 KB
testcase_16 AC 921 ms
4,348 KB
testcase_17 AC 918 ms
4,348 KB
testcase_18 AC 893 ms
4,348 KB
testcase_19 AC 918 ms
4,348 KB
testcase_20 AC 918 ms
4,348 KB
testcase_21 AC 918 ms
4,348 KB
testcase_22 AC 891 ms
4,348 KB
testcase_23 AC 917 ms
4,348 KB
testcase_24 AC 917 ms
4,348 KB
testcase_25 AC 916 ms
4,348 KB
testcase_26 AC 890 ms
4,348 KB
testcase_27 AC 917 ms
4,348 KB
testcase_28 AC 917 ms
4,348 KB
testcase_29 AC 919 ms
4,348 KB
testcase_30 AC 889 ms
4,348 KB
testcase_31 AC 919 ms
4,348 KB
testcase_32 AC 917 ms
4,348 KB
testcase_33 AC 22 ms
4,348 KB
testcase_34 AC 224 ms
4,348 KB
testcase_35 AC 453 ms
4,348 KB
testcase_36 AC 102 ms
4,348 KB
testcase_37 AC 50 ms
4,348 KB
testcase_38 AC 112 ms
4,348 KB
testcase_39 AC 103 ms
4,348 KB
testcase_40 AC 264 ms
4,348 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 140 ms
4,348 KB
testcase_43 AC 582 ms
4,348 KB
testcase_44 AC 651 ms
4,348 KB
testcase_45 AC 89 ms
4,348 KB
testcase_46 AC 189 ms
4,348 KB
testcase_47 AC 691 ms
4,348 KB
testcase_48 AC 190 ms
4,348 KB
testcase_49 AC 315 ms
4,348 KB
testcase_50 AC 390 ms
4,348 KB
testcase_51 AC 24 ms
4,348 KB
testcase_52 AC 244 ms
4,348 KB
testcase_53 AC 3 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
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 3 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 AC 2 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int h, w; cin >> h >> w;
  vector a(h + 2, vector(w + 2, 0)); FOR(i, 1, h + 1) FOR(j, 1, w + 1) cin >> a[i][j];
  vector<pair<int, int>> outside;
  REP(j, w + 2) outside.emplace_back(0, j);
  FOR(i, 1, h + 1) outside.emplace_back(i, 0);
  FOR(i, 1, h + 1) outside.emplace_back(i, w + 1);
  REP(j, w + 2) outside.emplace_back(h + 1, j);
  const int n = outside.size();
  int ans = 0;
  vector num(h + 2, vector(w + 2, 0));
  REP(i, n) FOR(dy1, -1, 2) FOR(dx1, -1, 2) {
    if (dy1 == 0 && dx1 == 0) continue;
    int score = 0;
    for (auto [y, x] = outside[i];
         0 <= y && y < h + 2 && 0 <= x && x < w + 2;
         y += dy1, x += dx1) {
      ++num[y][x];
      score += a[y][x];
    }
    FOR(j, i + 1, n) FOR(dy2, -1, 2) FOR(dx2, -1, 2) {
      if (dy2 == 0 && dx2 == 0) continue;
      int final_score = score;
      for (auto [y, x] = outside[j];
          0 <= y && y < h + 2 && 0 <= x && x < w + 2;
          y += dy2, x += dx2) {
        if (num[y][x]++ == 0) final_score += a[y][x];
      }
      chmax(ans, final_score);
      for (auto [y, x] = outside[j];
          0 <= y && y < h + 2 && 0 <= x && x < w + 2;
          y += dy2, x += dx2) {
        --num[y][x];
      }
    }
    for (auto [y, x] = outside[i];
         0 <= y && y < h + 2 && 0 <= x && x < w + 2;
         y += dy1, x += dx1) {
      --num[y][x];
    }
  }
  cout << ans << '\n';
  return 0;
}
0