| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 873028 | sleepntsheep | K개의 묶음 (IZhO14_blocks) | C++17 | 388 ms | 4184 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 100000
int n, k, a[N];
i64 dp[2][N], t[N<<1];
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
inline __attribute__((always_inline)) i64 qry(int l, int r)
{
i64 z = 1e18;
for (l += n, r += n + 1; l < r; l >>= 1, r>>=1)
{
if (l&1) z = min(z, t[l++]);
if (r&1) z = min(t[--r], z);
}
return z;
}
int main()
{
memset(dp, 63, sizeof dp);
ShinLena;
cin >> n >> k;
for (int i = 0, z = a[0]; i < n; ++i) cin >> a[i], z = max(z, a[i]), dp[0][i] = t[i+n] = z;
for (int i = n; i--;) t[i] = std::min(t[i<<1], t[i<<1|1]);
for (int j = 1; j < k; ++j)
{
stack<int> q;
for (int i = 0; i < n; ++i)
{
while (q.size() && a[q.top()] <= a[i]) q.pop();
i64 &d = dp[j&1][i];
d = 1e18;
if (q.size()) d = min({d, dp[j&1][q.top()], dp[j&1^1][q.top()] + a[i], qry(q.top() + 1, i-1) + a[i]});
else dp[j&1][i] = qry(0, i-1) + a[i];
q.push(i);
}
for (int i = 0; i < n; ++i) t[i+n] = dp[j&1][i];
for (int i = n; i--;) t[i] = std::min(t[i<<1], t[i<<1|1]);
}
cout << dp[k&1^1][n-1];
return 0;
}
컴파일 시 표준 에러 (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... | ||||
