結果

問題 No.2854 -1 Subsequence
ユーザー GOTKAKO
提出日時 2024-08-25 13:50:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 462 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 193,828 KB
最終ジャッジ日時 2025-02-24 00:59:16
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:24: warning: overflow in conversion from ‘double’ to ‘long long int’ changes value from ‘-1.0e+19’ to ‘-9223372036854775808’ [-Woverflow]
   14 |         long long nm = -1e19,np = -1e18;
      |                        ^~~~~

ソースコード

diff #

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

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

    int N; cin >> N;
    vector<int> A(N);
    for(auto &a : A) cin >> a;

    long long minus = 0,plus = -1e18;
    for(int i=0; i<N; i++){
        long long nm = -1e19,np = -1e18;
        nm = max(minus,plus+A.at(i));
        np = max(plus,minus-A.at(i));
        swap(minus,nm); swap(plus,np);
    }
    cout << max(minus,plus) << endl;
}
0