結果

問題 No.3597 Queen Score Attack 2
コンテスト
ユーザー GOTKAKO
提出日時 2026-07-24 21:10:43
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 75 ms / 2,000 ms
+ 413µs
コード長 680 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,168 ms
コンパイル使用メモリ 215,328 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2026-07-24 21:10:51
合計ジャッジ時間 5,303 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int H,W; cin >> H >> W;
    int sx,sy; cin >> sx >> sy;
    int N; cin >> N;
    vector<pair<int,int>> XY(N+1);
    XY.at(0) = {sx,sy};

    vector<long long> dp(N+1);
    for(int i=1; i<=N; i++){
        int x,y,c; cin >> x >> y >> c;
        auto [bx,by] = XY.at(i-1);
        if(x == bx || y == by || (abs(x-bx) == abs(y-by))) dp.at(i) = max(dp.at(i),dp.at(i-1)+c);
        if(i >= 2) dp.at(i) = max(dp.at(i),dp.at(i-2)+c),dp.at(i-1) = max(dp.at(i-1),dp.at(i-2));
        XY.at(i) = {x,y};
    }

    cout << *max_element(dp.begin(),dp.end()) << endl;
}
0