結果

問題 No.921 ずんだアロー
ユーザー CleyLCleyL
提出日時 2019-11-08 22:34:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 666 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 70,368 KB
実行使用メモリ 4,776 KB
最終ジャッジ日時 2023-10-13 04:08:08
合計ジャッジ時間 2,162 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 26 ms
4,744 KB
testcase_11 AC 28 ms
4,776 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 20 ms
4,372 KB
testcase_14 AC 23 ms
4,368 KB
testcase_15 AC 14 ms
4,356 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 24 ms
4,624 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 29 ms
4,724 KB
testcase_24 AC 28 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int dp[100000][2];//dp[i番目][0=隣に置けない,1=隣において良い] = 最大値
int main(){
  int n;cin>>n;
  vector<int> a(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  vector<int> b;
  int tmp = 1;
  for(int i = 1; n > i; i++){
    if(a[i-1] != a[i]){
      b.push_back(tmp);
      tmp = 1;
    }else{
      tmp++;
    }
  }
  b.push_back(tmp);
  int mx = 0;
  dp[0][0] = b[0];
  dp[0][1] = 0;
  for(int i= 1; b.size() > i; i++){
    dp[i][0] = max(dp[i-1][0],dp[i-1][1]+b[i]);
    dp[i][1] = max(dp[i-1][0],dp[i-1][1]);
  }
  cout << max(dp[b.size()-1][0],dp[b.size()-1][1]) << endl;
}
0