Submission #1031737

#TimeUsernameProblemLanguageResultExecution timeMemory
1031737juicyJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 2e5 + 5; int n, k; string s; array<int, 3> nxt[N]; int conv(char c) { return c == 'J' ? 0 : (c == 'O' ? 1 : 2); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k >> s; array<int, 3> lst = {n + 1, n + 1, n + 1}; for (int i = n; i >= 1; --i) { nxt[i] = lst; lst[conv(s[i - 1])] = i; } nxt[0] = lst; int p = 0; for (int j = 0; j < 3; ++j) { for (int i = 0; i < k; ++i) { p = nxt[p][j]; if (p == n + 1) { cout << -1; exit(0); } } } cout << n - k * 3 - nxt[0][0] + 1 - n + p; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...