結果

問題 No.921 ずんだアロー
ユーザー LayCurseLayCurse
提出日時 2019-11-10 18:29:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,513 bytes
コンパイル時間 2,397 ms
コンパイル使用メモリ 209,312 KB
実行使用メモリ 4,664 KB
最終ジャッジ日時 2023-10-13 07:50:00
合計ジャッジ時間 3,713 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 3 ms
4,608 KB
testcase_11 AC 4 ms
4,532 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 3 ms
4,564 KB
testcase_19 AC 4 ms
4,500 KB
testcase_20 AC 4 ms
4,620 KB
testcase_21 AC 4 ms
4,496 KB
testcase_22 AC 4 ms
4,664 KB
testcase_23 AC 4 ms
4,616 KB
testcase_24 AC 4 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(double x){
  printf("%.15f",x);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    putchar_unlocked(x[i]);
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[100000];
int dp1[100000];
int dp2[100000];
int main(){
  int i;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  dp2[0] = 1;
  for(i=(1);i<(N);i++){
    dp1[i] =max_L(dp1[i-1], dp2[i-1]);
    dp2[i] = dp1[i-1] + 1;
    if(A[i-1] == A[i]){
      chmax(dp2[i], dp2[i-1] + 1);
    }
  }
  wt_L(max_L(dp1[N-1], dp2[N-1]));
  wt_L('\n');
  return 0;
}
// cLay varsion 20191108-1

// --- original code ---
// int N, A[1d5];
// int dp1[1d5], dp2[1d5];
// {
//   rd(N,A(N));
//   dp2[0] = 1;
//   rep(i,1,N){
//     dp1[i] = max(dp1[i-1], dp2[i-1]);
//     dp2[i] = dp1[i-1] + 1;
//     if(A[i-1] == A[i]) dp2[i] >?= dp2[i-1] + 1;
//   }
//   wt(max(dp1[N-1], dp2[N-1]));
// }
0