結果
問題 |
No.2509 Beam Shateki
|
ユーザー |
👑 ![]() |
提出日時 | 2023-10-20 21:31:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,675 bytes |
コンパイル時間 | 918 ms |
コンパイル使用メモリ | 84,544 KB |
最終ジャッジ日時 | 2025-02-17 08:38:34 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 61 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <atcoder/modint> using Modint = atcoder::static_modint<998244353>; using namespace std; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; void testcase(){ int H, W; cin >> H >> W; vector<vector<int>> A(H, vector<int>(W)); rep(y,H) rep(x,W) cin >> A[y][x]; auto f = [&](vector<vector<int>> B) -> int { vector<int> Z(H),X(W),C(H+W),V(H+W); rep(y,H) rep(x,W){ int a = B[y][x]; Z[y] += a; X[x] += a; C[y+x] += a; V[y-x+W] += a; } int ans = 0; ans = max(ans, *max_element(Z.begin(), Z.end())); ans = max(ans, *max_element(X.begin(), X.end())); ans = max(ans, *max_element(C.begin(), C.end())); ans = max(ans, *max_element(V.begin(), V.end())); return ans; }; int ans = 0; rep(tt,2){ rep(y,H){ vector<vector<int>> B = A; int t = 0; rep(x,W){ t += B[y][x]; B[y][x] = 0; } ans = max(ans, t + f(move(B))); } rep(d,H+W-1){ vector<vector<int>> B = A; int t = 0; rep(x,W) if(x<=d && d-x<H){ t += B[d-x][x]; B[d-x][x] = 0; } ans = max(ans, t + f(move(B))); } vector<vector<int>> buf(W, vector<int>(H)); rep(y,H) rep(x,W) buf[x][y] = A[H-1-y][x]; swap(A,buf); swap(H,W); } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }