結果

問題 No.2509 Beam Shateki
ユーザー tama04tama04
提出日時 2023-10-24 18:35:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,198 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 182,360 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-10-24 18:35:49
合計ジャッジ時間 30,230 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,964 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0