結果

問題 No.2055 12x34...
ユーザー Nzt3
提出日時 2022-09-25 20:02:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 408 bytes
コンパイル時間 2,219 ms
コンパイル使用メモリ 201,744 KB
最終ジャッジ日時 2025-02-07 15:05:16
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<int>A(N);
  for(int &i:A)cin>>i;
  map<int,unsigned>cnt;
  unsigned ans=0;
  for(int i=0;i<N;i++){
    ans=min(ans+cnt[A[i]-1],ans+cnt[A[i]-1]-mod);
    cnt[A[i]]=min(cnt[A[i]]+cnt[A[i]-1]+1,cnt[A[i]]+cnt[A[i]-1]+1-mod);
  }
  cout<<ans<<'\n';
}
0