# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
886477 | boris_mihov | Money (IZhO17_money) | C++17 | 1 ms | 6492 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <bitset>
#include <vector>
#include <stack>
typedef long long llong;
const int MAXN = 1000000 + 10;
int n;
int a[MAXN];
int b[MAXN];
int prev[MAXN];
bool endHere[MAXN];
std::stack <int> st;
void solve()
{
std::iota(b + 1, b + 1 + n, 1);
std::sort(b + 1, b + 1 + n, [&](int x, int y)
{
return a[x] < a[y] || (a[x] == a[y] & x < y);
});
for (int i = 1 ; i <= n ; ++i)
{
a[b[i]] = i;
}
for (int i = 1 ; i <= n ; ++i)
{
while (st.size() && a[st.top()] > a[i])
{
st.pop();
}
if (st.size())
{
prev[i] = st.top();
}
st.push(i);
}
int ans = n;
for (int i = 1 ; i <= n ; ++i)
{
endHere[b[i]] = true;
// std::cout << "here: " << b[i] << ' ' << a[b[i]] << ' ' << prev[b[i]] << ' ' << endHere[prev[b[i]]] << ' ' << i - (n - ans + endHere[prev[b[i]]]) << '\n';
if (endHere[prev[b[i]]])
{
ans--;
endHere[prev[b[i]]] = false;
}
}
std::cout << ans << '\n';
}
void input()
{
std::cin >> n;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
return 0;
}
/*
8
7 6 8 1 5 2 4 3
7 | 5 7 | 1 4 | 1 2 | 1
1 | 1 |1 2| 4 | 5 7 | 7
7 5 7 1 4 1 2 1
5
7 | 5 7 | 1 5 2 4 3
*/
컴파일 시 표준 에러 (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... |