# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36244 | touristk2000 | Money (IZhO17_money) | C++14 | 556 ms | 17648 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 <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e6 + 1;
int main(){
int n;
scanf("%d", &n);
vector<int> a(n);
vector<int> cnt(MAXN);
for (int i = 0; i < n; ++i)
{
scanf("%d", &a[i]);
cnt[a[i]]++;
}
vector<int> pr(MAXN + 1), nxt(MAXN + 1, MAXN);
{
int lst = 0;
for (int i = 1; i <= MAXN; ++i)
{
pr[i] = lst;
if (cnt[i])
nxt[lst] = i, lst = i;
}
}
int ans = 0;
for (int i = n - 1; i >= 0;)
{
++ans;
int j = i;
while (i > 0)
{
int p = pr[a[i]];
if (a[i - 1] == a[i])
{
if (cnt[a[i]] == 1)
{
int l = pr[a[i]];
int r = nxt[a[i]];
pr[r] = l;
nxt[l] = r;
}
--cnt[a[i]];
--i;
}
else
{
if (p == a[i - 1] && (cnt[a[i]] == 1 || a[j] == a[i]))
{
if (cnt[a[i]] == 1)
{
int l = pr[a[i]];
int r = nxt[a[i]];
pr[r] = l;
nxt[l] = r;
}
--cnt[a[i]];
--i;
}
else
{
break;
}
}
}
if (cnt[a[i]] == 1)
{
int l = pr[a[i]];
int r = nxt[a[i]];
pr[r] = l;
nxt[l] = r;
}
--cnt[a[i]];
--i;
}
printf("%d\n", ans);
return 0;
}
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... |