Submission #669262

#TimeUsernameProblemLanguageResultExecution timeMemory
669262GrandTiger1729JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
8 ms868 KiB
#include <iostream> using namespace std; int val(char c){ if (c == 'J') return 0; if (c == 'O') return 1; if (c == 'I') return 2; } const int INF = 1e9 + 9; int main(){ cin.tie(0)->sync_with_stdio(0); int n, k; cin >> n >> k; string s; cin >> s; int l[3]{}, r[3]{}, cnt[3]{}; int ans = INF; while (true){ while (r[0] < n && cnt[0] < k){ if (val(s[r[0]++]) == 0) cnt[0]++; } while (l[1] < r[0]){ if (val(s[l[1]++]) == 1) cnt[1]--; } while (r[1] < n && cnt[1] < k){ if (val(s[r[1]++]) == 1) cnt[1]++; } while (l[2] < r[1]){ if (val(s[l[2]++]) == 2) cnt[2]--; } while (r[2] < n && cnt[2] < k){ if (val(s[r[2]++]) == 2) cnt[2]++; } if (cnt[0] < k || cnt[1] < k || cnt[2] < k) break; ans = min(ans, r[2] - l[0] - 3 * k); if (val(s[l[0]++]) == 0) cnt[0]--; } cout << (ans == INF? -1: ans); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int val(char)':
ho_t2.cpp:8:1: warning: control reaches end of non-void function [-Wreturn-type]
    8 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...