Submission #9245342


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n;
    cin >> n;
    vector<ll> a(n);
    for (auto& e : a) {
        cin >> e;
    }
    vector<ll> dp(n, INF);
    for (int i = 0; i < n; i++)
    {
        *lower_bound(dp.begin(), dp.begin() + n, a[i]) = a[i];
        //fill(upper_bound(dp.begin(), dp.begin() + n, a[i]), dp.end(), INF);
    }

    if (dp[0] != 1) {
        cout << -1 << endl;
        return 0;
    }

    //ll ans = dp.end() - lower_bound(dp.begin(), dp.begin() + n, INF);
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        if (dp[i] == i + 1ll) {
            ans++;
        }
        else {
            break;
        }
    }
    cout << n - ans << "\n";
    return 0;
}

Submission Info

Submission Time
Task D - Brick Break
User mmatthew_43
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1456 Byte
Status
Exec Time 30 ms
Memory 3328 KB

Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 sample_01, sample_02, sample_03, sample_04, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_2, testcase_20, testcase_21, testcase_3, testcase_4, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9
Sample 0 / 0 sample_01, sample_02, sample_03, sample_04
Case Name Status Exec Time Memory
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB
sample_03 1 ms 256 KB
sample_04 1 ms 256 KB
testcase_0 11 ms 1408 KB
testcase_1 23 ms 2688 KB
testcase_10 22 ms 3328 KB
testcase_11 28 ms 3328 KB
testcase_12 28 ms 3328 KB
testcase_13 28 ms 3328 KB
testcase_14 28 ms 3328 KB
testcase_15 28 ms 3328 KB
testcase_16 28 ms 3328 KB
testcase_17 28 ms 3328 KB
testcase_18 28 ms 3328 KB
testcase_19 28 ms 3328 KB
testcase_2 30 ms 3328 KB
testcase_20 28 ms 3328 KB
testcase_21 28 ms 3328 KB
testcase_3 23 ms 2688 KB
testcase_4 21 ms 2560 KB
testcase_5 30 ms 3328 KB
testcase_6 20 ms 2432 KB
testcase_7 4 ms 640 KB
testcase_8 28 ms 3328 KB
testcase_9 17 ms 3328 KB