結果

問題 No.992 最長増加部分列の数え上げ
ユーザー 👑 Nachia
提出日時 2020-12-10 23:11:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 196,156 KB
最終ジャッジ日時 2025-01-16 21:40:24
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 7 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0;i<(n);i++)

const ULL M=1000000007;

int main(){
  int N; cin>>N;
  vector<int> A(N); rep(i,N) cin>>A[i];
  vector<int> lisT(N+1,1000000001);
  vector<int> I(N);
  int p=0;
  rep(i,N){
    int l=0, r=N+1;
    while(r-l>1){
      int m=(l+r)/2;
      if(lisT[m-1]<A[i]) l=m; else r=m;
    }
    lisT[l]=A[i];
    I[i]=l+1;
    p=max(p,l+1);
  }
  vector<int> pre(p+1,-1);
  pre[0]=0;
  vector<ULL> dp(N+1);
  dp[0]=1;
  rep(i,N){
    if(pre[I[i]]!=-1) dp[i+1]+=dp[pre[I[i]]];
    if(pre[I[i]-1]!=-1) dp[i+1]+=dp[pre[I[i]-1]];
    dp[i+1]%=M;
    pre[I[i]]=i+1;
  }
  cout<<dp[N]<<endl;
  return 0;
}
0