# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
953726 | Angus_Yeung | JJOOII 2 (JOI20_ho_t2) | C++17 | 10 ms | 7516 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<ll, ll>
typedef long long ll;
const ll MOD = 1000000007LL;
const ll INF = 1e15;
using namespace std;
ll n, k, ans;
ll dp[5][200010];
char a[200010];
deque<ll> q;
int main() {
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
dp[1][0] = dp[2][0] = dp[3][0] = INF;
for (int j = 1; j <= 3; j++) {
while (!q.empty()) q.pop_back();
for (int i = 1; i <= n; i++) {
if (j == 1 && a[i] == 'J') q.push_back(i);
if (j == 2 && a[i] == 'O') q.push_back(i);
if (j == 3 && a[i] == 'I') q.push_back(i);
while (q.size() > k) q.pop_front();
if (q.size() < k) dp[j][i] = INF;
else dp[j][i] = dp[j-1][q.front()-1]+(i-q.front()+1-k);
}
}
ans = INF;
for (int i = 0; i <= n; i++) ans = min(ans, dp[3][i]);
if (ans == INF) cout << "-1\n";
else cout << ans << "\n";
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... |