結果
| 問題 |
No.2509 Beam Shateki
|
| コンテスト | |
| ユーザー |
tama04
|
| 提出日時 | 2023-10-24 18:35:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,198 bytes |
| コンパイル時間 | 2,035 ms |
| コンパイル使用メモリ | 182,948 KB |
| 実行使用メモリ | 13,884 KB |
| 最終ジャッジ日時 | 2024-09-24 11:41:00 |
| 合計ジャッジ時間 | 29,545 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 11 -- * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else { return false; } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else { return false; } }
#define rep(i, s, n) for(int i = (s); i < n; i++)
#define reps(i, s, n) for(int i = (s); i <= n; i++)
#define rrep(i, n, s) for(int i = n; i >= (s); i--)
#define all(x) (x).begin(), (x).end()
#define print(V) for (int z = 0; z < (V).size(); z++) { cout << V[z] << " "; } cout << endl;
#define MOD 998244353
#define MOD2 1000000007
#define INF 1LL << 60
#define PI acos(-1)
int h, w;
vector< vector<int> > A;
vector< vector<bool> > seen;
vector< vector<int> > vec;
int vx[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int vy[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
ll calc(int x, int y, int s, bool flag) {
ll res = 0;
while (1) {
x += vx[s];
y += vy[s];
if (x < 0 || x >= h + 2) {
break;
}
if (y < 0 || y >= w + 2) {
break;
}
if (!seen[x][y]) {
res += A[x][y];
if (flag) {
seen[x][y] = true;
}
}
}
return res;
}
ll solve(vector<int> d1, vector<int> d2) {
ll res = 0;
ll d1_calc = 0, d2_calc = 0;
rep(i, 0, 8) {
seen.assign(h + 2, vector<bool>(w + 2, false));
d1_calc = calc(d1[0], d1[1], i, true);
rep(j, 0, 8) {
d2_calc = calc(d2[0], d2[1], j, false);
chmax(res, d1_calc + d2_calc);
}
}
return res;
}
int main(void) {
cin >> h >> w;
A.assign(h + 2, vector<int>(w + 2));
rep(i, 1, h + 1) {
rep(j, 1, w + 1) {
cin >> A[i][j];
}
}
vector<int> p(2); //[0]: x座標, [1]: y座標
rep(i, 0, h + 2) {
if (i == 0 || i == h + 1) {
rep(j, 0, w + 2) {
p[0] = i;
p[1] = j;
vec.push_back(p);
}
}
else {
for (int j = 0; j < w + 2; j += (w + 1)) {
p[0] = i;
p[1] = j;
vec.push_back(p);
}
}
}
//rep(i, 0, vec.size()) {
// print(vec[i]);
//}
seen.assign(h + 2, vector<bool>(w + 2, false));
int vs = vec.size();
ll ans = 0;
rep(i, 0, vs) {
rep(j, 0, vs) {
if (i == j) {
continue;
}
chmax(ans, solve(vec[i], vec[j]));
}
}
cout << ans << endl;
return 0;
}
tama04