結果
| 問題 | No.3597 Queen Score Attack 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-24 22:58:45 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 77 ms / 2,000 ms |
| + 200µs | |
| コード長 | 715 bytes |
| 記録 | |
| コンパイル時間 | 1,134 ms |
| コンパイル使用メモリ | 212,768 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2026-07-24 22:58:51 |
| 合計ジャッジ時間 | 5,685 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
bool f(ll x,ll y,ll xx,ll yy){
if(x==xx || y==yy || llabs(x-xx)==llabs(yy-y)) return true;
else return false;
}
ll dp[500010];
int main(void){
cin.tie(nullptr); ios_base::sync_with_stdio(false);
ll i,j;
ll H,W,sx,sy,N;
cin >> H >> W >> sx >> sy >> N;
vector<ll> x(N+1,0),y(N+1,0),c(N+1,0);
for(i=1;i<=N;i++)cin >> x[i] >> y[i] >> c[i];
if(f(sx,sy,x[1],y[1])) dp[1]=c[1];
for(i=2;i<=N;i++){
if(f(x[i-1],y[i-1],x[i],y[i])) dp[i]=max(dp[i-1]+c[i],dp[i-2]+c[i]);
else dp[i]=max(dp[i-2]+c[i],dp[i-1]);
}
cout << dp[N] << endl;
return 0;
}