結果

問題 No.2854 -1 Subsequence
コンテスト
ユーザー MM
提出日時 2024-08-25 14:09:03
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 853 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,329 ms
コンパイル使用メモリ 376,940 KB
実行使用メモリ 16,032 KB
最終ジャッジ日時 2026-04-03 22:34:45
合計ジャッジ時間 6,981 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:23:42: warning: integer overflow in expression of type 'long long int' results in '-9223372036854775808' [-Woverflow]
   23 |   vector<vector<ll>> dp(N+1,vector<ll>(2,-INF));
      |                                          ^~~~
main.cpp:26:19: warning: integer overflow in expression of type 'long long int' results in '-9223372036854775808' [-Woverflow]
   26 |     if(dp[i][0] > -INF){
      |                   ^~~~
main.cpp:30:19: warning: integer overflow in expression of type 'long long int' results in '-9223372036854775808' [-Woverflow]
   30 |     if(dp[i][1] > -INF){
      |                   ^~~~

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/all>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
using namespace std;
using namespace atcoder;
using ll = long long;
const ll mod = 998244353;
using mint = modint998244353;
using Graph = vector<vector<int>>;

const vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};

int main(){
  // input
  int N; cin >> N;
  vector<ll> A(N);
  for(int i = 0; i < N; i++)
    cin >> A[i];
    
  // solve
  const ll INF = 1LL<<63;
  vector<vector<ll>> dp(N+1,vector<ll>(2,-INF));
  dp[0][0] = 0;
  for(int i = 0; i < N; i++){
    if(dp[i][0] > -INF){
      chmax(dp[i+1][0],dp[i][0]);
      chmax(dp[i+1][1],dp[i][0] - A[i]);
    }
    if(dp[i][1] > -INF){
      chmax(dp[i+1][1],dp[i][1]);
      chmax(dp[i+1][0],dp[i][1] + A[i]);
    }
  }
  
  // output
  cout << max(dp[N][0],dp[N][1]) << endl;
}
0