# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
759636 |
2023-06-16T13:45:15 Z |
raysh07 |
Money (IZhO17_money) |
C++17 |
|
1 ms |
212 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
void Solve()
{
int n; cin >> n;
vector <int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
vector <int> curr;
set <int> gone;
vector <int> dp(n + 1, INF);
dp[0] = 0;
for (int i = 1; i <= n; i++){
if (curr.size() == 0 || a[i] >= curr.back()){
curr.push_back(a[i]);
} else {
for (auto x : curr) gone.insert(x);
curr.clear();
curr.push_back(a[i]);
}
auto id = gone.upper_bound(a[i]);
if (id == gone.begin()){
dp[i] = dp[i - curr.size()] + 1;
// cout << "SMH\n";
continue;
}
--id;
int found = *id;
int holy = curr.end() - lower_bound(curr.begin(), curr.end(), found);
// cout << holy << " " << curr.size() << "\n";
dp[i] = dp[i - holy] + 1;
}
// for (int i = 1; i <= n; i++) cout << dp[i] << " \n"[i == n];
cout << dp[n] << "\n";
}
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |