結果
問題 | No.2509 Beam Shateki |
ユーザー |
👑 ![]() |
提出日時 | 2023-10-20 23:14:39 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 869 ms / 2,000 ms |
コード長 | 2,234 bytes |
コンパイル時間 | 3,061 ms |
コンパイル使用メモリ | 255,740 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-20 22:39:18 |
合計ジャッジ時間 | 26,980 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 61 |
ソースコード
#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;}