이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <chrono>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <random>
#include <cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll N = 500007;
ll n, m, k;
ll a[N];
ll dp1[N], dp2[N];
ll rs[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] <= k)rs[i] = max(ll(i), min(n, i + (k - a[i])));
else rs[i] = 0;
}
int j = 1;
for (int _ = 0; _ < m; _++) {
ll cur = 0;
j = 1;
for (int i = 1; i <= n; i++) {
cur = max(cur, rs[i]);
dp1[i] = dp1[i - 1] + (cur >= i);
}
stack<int>st;
for (int i = n; i >= 1; i--) {
dp2[i] = dp2[i + 1];
st.push(i);
while (!st.empty() && st.top() <= rs[i]) {
dp2[i]++;
st.pop();
}
}
int mx = MOD;
for (int i = 1; i <= n; i++) {
if (dp1[i - 1] + dp2[i] < mx) {
mx = dp1[i - 1] + dp2[i];
j = i;
}
//cout << dp1[i - 1] + dp2[i] << " ";
}
for (int i = 1; i < j; i++) {
rs[i] = min(rs[i], ll(j - 1));
}
}
cout << dp1[j - 1] + dp2[j] << endl;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |