結果

問題 No.711 競技レーティング単調増加
ユーザー kimiyuki
提出日時 2018-06-30 02:07:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 195,596 KB
最終ジャッジ日時 2025-01-06 11:48:03
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <typename T>
vector<T> longest_weak_increasing_subsequence(vector<T> const & xs) {
    vector<T> l;  // l[i] is the last element of the increasing subsequence whose length is i + 1
    for (auto && x : xs) {
        auto it = upper_bound(l.begin(), l.end(), x);
        if (it == l.end()) {
            l.push_back(x);
        } else {
            *it = x;
        }
    }
    return l;
}

int main() {
    // input
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) cin >> a[i];

    // solve
    vector<int> b;
    REP (i, n) {
        int b_i = a[i] - i;
        if (b_i >= 1) b.push_back(b_i);
    }
    int answer = n - longest_weak_increasing_subsequence(b).size();

    // output
    cout << answer << endl;
    return 0;
}
0