結果
| 問題 | No.3597 Queen Score Attack 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-24 22:17:16 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| + 797µs | |
| コード長 | 1,685 bytes |
| 記録 | |
| コンパイル時間 | 2,101 ms |
| コンパイル使用メモリ | 336,864 KB |
| 実行使用メモリ | 13,308 KB |
| 最終ジャッジ日時 | 2026-07-24 22:21:00 |
| 合計ジャッジ時間 | 6,331 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#ifdef Doludu
template <typename T>
ostream& operator << (ostream &o, vector <T> vec) {
o << "{"; int f = 0;
for (T i : vec) o << (f++ ? " " : "") << i;
return o << "}";
}
void bug__(int c, auto ...a) {
cerr << "\e[1;" << c << "m";
(..., (cerr << a << " "));
cerr << "\e[0m" << endl;
}
#define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x)
#define bug(x...) bug_(32, x)
#define bugv(x...) bug_(36, vector(x))
#define safe bug_(33, "safe")
#else
#define bug(x...) void(0)
#define bugv(x...) void(0)
#define safe void(0)
#endif
const int mod = 998244353, N = 300005;
void solve() {
int n, m, x, y;
cin >> n >> m >> x >> y;
vector <array <int, 3>> arr;
arr.pb({x, y, 0});
int k;
cin >> k;
for (int i = 0, w; i < k; ++i) {
cin >> x >> y >> w;
arr.pb({x, y, w});
}
auto good = [&](int x1, int y1, int x2, int y2) {
return x1 == x2 || y1 == y2 || x1 + y1 == x2 + y2 || x1 - y1 == x2 - y2;
};
vector <ll> dp(k + 1, -1ll << 60);
dp[0] = 0;
ll pre = -1ll << 60;
for (int i = 1; i <= k; ++i) {
if (good(arr[i - 1][0], arr[i - 1][1], arr[i][0], arr[i][1])) {
dp[i] = max(dp[i], dp[i - 1] + arr[i][2]);
}
dp[i] = max(dp[i], pre + arr[i][2]);
pre = max(pre, dp[i - 1]);
}
cout << *max_element(all(dp)) << "\n";
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}