結果

問題 No.921 ずんだアロー
ユーザー amaridekinai
提出日時 2019-11-21 22:34:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 59,200 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 02:26:04
合計ジャッジ時間 2,088 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~
main.cpp:14:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |   for(int i = 0; i < n; i++){ scanf("%d", &a[i]);}
      |                               ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int dp[100100][2]; //
int a[100100];

void chmax(int &a, int b){ if( a < b){swap(a,b);} return ;}

int main(){
  int n; scanf("%d", &n);
  for(int i = 0; i < n; i++){ scanf("%d", &a[i]);}
  
  dp[0][1] = 1;
  //dynamic programming
  for(int i = 0; i < n-1; i++){
    chmax(dp[i+1][0], dp[i][1]);
    chmax(dp[i+1][0], dp[i][0]);
    chmax(dp[i+1][1], dp[i][0]+1);
    if( a[i] == a[i+1]){
      chmax(dp[i+1][1], dp[i][1]+1);
    }
  }
  
  int res = max(dp[n-1][0],dp[n-1][1]);
  
  printf("%d\n", res);
  
  return 0;
}
0