# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879625 | alex_2008 | Money (IZhO17_money) | C++14 | 1036 ms | 69784 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <fstream>
#include <random>
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N = 1e6 + 10;
int a[N], dp[N], down[N];
int f[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[0] = 0;
dp[1] = 1;
down[1] = 1;
for (int i = 2; i <= n; i++) {
down[i] = (a[i] < a[i - 1]) ? i : down[i - 1];
}
set <int> ms;
for (int i = 1; i <= n; i++) {
auto it = ms.upper_bound(a[i]);
if (it == ms.end()) {
f[i] = 10000000;
}
else f[i] = *it;
ms.insert(a[i]);
}
for (int i = 2; i <= n; i++) {
int l = down[i], r = i;
while (l <= r) {
int mid = (l + r) / 2;
bool check = true;
int R = 10000000;
if (f[mid] < a[i]) check = false;
if (check) {
dp[i] = dp[mid - 1] + 1;
r = mid - 1;
}
else l = mid + 1;
}
}
cout << dp[n] << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |