# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
570664 | YouAreMyGalaxy | K개의 묶음 (IZhO14_blocks) | C++17 | 179 ms | 41204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 1e5, K = 1e2;
int dp[N + 1][K + 1], a[N + 1], n, k;
stack<pair<int, int> > St;
void read()
{
cin >> n >> k;
for (int i = 1, j = 0; i <= n; ++ i)
{
cin >> a[i];
j = max(j, a[i]);
dp[i][1] = j;
}
}
void solve()
{
for (int j = 2; j <= k; ++ j)
{
while(!St.empty())
{
St.pop();
}
for (int i = j; i <= n; ++ i)
{
dp[i][j] = dp[i - 1][j - 1];
while(!St.empty() && a[i] >= St.top().first)
{
//cerr << St.top().first << ' ' << St.top().second << '\n';
dp[i][j] = min(dp[i][j], St.top().second);
St.pop();
}
if (St.empty() || dp[i][j] + a[i] < St.top().first + St.top().second)
{
St.push({a[i], dp[i][j]});
}
//cerr << dp[i][j] << ' ';
dp[i][j] = St.top().first + St.top().second;
}
}
cout << dp[n][k];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
컴파일 시 표준 에러 (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... |