Please sign in first.
Submission #39185216
Source Code Expand
#include <bits/stdc++.h> using namespace std; int n, k; string s; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k >> s; int num = 0, ans = 0; for (auto c : s) num += (c == 'X'); if (num == n) { cout << max(0, k - 1) << endl; exit(0); } if (num == 0) { cout << max(0, n - 1 - k) << endl; exit(0); } if (num >= k) { priority_queue<int, vector<int>, greater<int>> p; for (int i = 0, j; i < n; i = j + 1) { j = i; while (j + 1 < n && s[j + 1] == s[j]) j++; if (s[i] == 'X') { if (i != 0 && j != n - 1) p.push(j - i + 1); } else { ans += j - i; } } while (!p.empty() && k >= p.top()) { k -= p.top(); ans += p.top() + 1; p.pop(); } ans += k; cout << ans << '\n'; } else { k -= num; ans = n - 1; priority_queue<int> p; for (int i = 0, j; i < n; i = j + 1) { j = i; while (j + 1 < n && s[j + 1] == s[j]) j++; if (s[i] == 'Y') { if (i != 0 && j != n - 1) p.push(j - i + 1); else { ans -= min(k, j - i + 1); k -= min(k, j - i + 1); } } } while (k) { ans -= min(k, p.top()) + 1; k -= min(k, p.top()); p.pop(); } cout << ans << '\n'; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - XYYYX |
User | swiftc |
Language | C++ (GCC 9.2.1) |
Score | 500 |
Code Size | 1365 Byte |
Status | AC |
Exec Time | 12 ms |
Memory | 4072 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00-sample-001.txt, 00-sample-002.txt |
All | 00-sample-001.txt, 00-sample-002.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt, 01-043.txt, 01-044.txt, 01-045.txt, 01-046.txt, 01-047.txt, 01-048.txt, 01-049.txt, 01-050.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00-sample-001.txt | AC | 6 ms | 3528 KiB |
00-sample-002.txt | AC | 2 ms | 3468 KiB |
01-001.txt | AC | 2 ms | 3504 KiB |
01-002.txt | AC | 1 ms | 3468 KiB |
01-003.txt | AC | 2 ms | 3480 KiB |
01-004.txt | AC | 2 ms | 3456 KiB |
01-005.txt | AC | 2 ms | 3584 KiB |
01-006.txt | AC | 2 ms | 3456 KiB |
01-007.txt | AC | 2 ms | 3604 KiB |
01-008.txt | AC | 2 ms | 3608 KiB |
01-009.txt | AC | 2 ms | 3576 KiB |
01-010.txt | AC | 2 ms | 3532 KiB |
01-011.txt | AC | 8 ms | 3792 KiB |
01-012.txt | AC | 8 ms | 3728 KiB |
01-013.txt | AC | 10 ms | 3860 KiB |
01-014.txt | AC | 4 ms | 3604 KiB |
01-015.txt | AC | 6 ms | 3744 KiB |
01-016.txt | AC | 7 ms | 3600 KiB |
01-017.txt | AC | 5 ms | 3712 KiB |
01-018.txt | AC | 7 ms | 3560 KiB |
01-019.txt | AC | 5 ms | 3700 KiB |
01-020.txt | AC | 6 ms | 3552 KiB |
01-021.txt | AC | 4 ms | 3716 KiB |
01-022.txt | AC | 3 ms | 3552 KiB |
01-023.txt | AC | 4 ms | 3584 KiB |
01-024.txt | AC | 6 ms | 3724 KiB |
01-025.txt | AC | 6 ms | 3688 KiB |
01-026.txt | AC | 6 ms | 3792 KiB |
01-027.txt | AC | 8 ms | 3788 KiB |
01-028.txt | AC | 9 ms | 3784 KiB |
01-029.txt | AC | 8 ms | 3972 KiB |
01-030.txt | AC | 12 ms | 4068 KiB |
01-031.txt | AC | 12 ms | 4072 KiB |
01-032.txt | AC | 5 ms | 3660 KiB |
01-033.txt | AC | 3 ms | 3592 KiB |
01-034.txt | AC | 5 ms | 3716 KiB |
01-035.txt | AC | 12 ms | 4072 KiB |
01-036.txt | AC | 6 ms | 4028 KiB |
01-037.txt | AC | 11 ms | 3968 KiB |
01-038.txt | AC | 4 ms | 3588 KiB |
01-039.txt | AC | 2 ms | 3712 KiB |
01-040.txt | AC | 3 ms | 3664 KiB |
01-041.txt | AC | 7 ms | 3580 KiB |
01-042.txt | AC | 5 ms | 3724 KiB |
01-043.txt | AC | 4 ms | 3728 KiB |
01-044.txt | AC | 4 ms | 3556 KiB |
01-045.txt | AC | 3 ms | 3588 KiB |
01-046.txt | AC | 3 ms | 3660 KiB |
01-047.txt | AC | 4 ms | 3712 KiB |
01-048.txt | AC | 3 ms | 3700 KiB |
01-049.txt | AC | 4 ms | 3536 KiB |
01-050.txt | AC | 2 ms | 3472 KiB |