Submission #956135

#TimeUsernameProblemLanguageResultExecution timeMemory
956135samvar_0907JJOOII 2 (JOI20_ho_t2)C++17
13 / 100
2009 ms1312 KiB
#include<bits/stdc++.h> using namespace std; int main(){ // Input : n - length, k - level, s - string int n, k; cin >> n >> k; std::string s; cin >> s; // Target string std::string opt = ""; for(int i = 0; i < k; i++){ opt += 'J'; } for(int i = 0; i < k; i++){ opt += 'O'; } for(int i = 0; i < k; i++){ opt += 'I'; } int ans = INT_MAX; // since we want the minimum operations, this is max // so that any min(ans, mismatch) will decrease it // if it doesnt (at end) we know that the output cant be reached for (int i = 0; i <= n; i++){ if (s[i] == 'J'){ // j is the character with which opt has to begin int pointer = 0; int mismatch = 0; for (int j = i; j <= n; j++){ if (s[j] == opt[pointer]){ // match pointer++; } else{ mismatch++; // mismatch } if (pointer == 3*k){ // end of the string ans = min(ans, mismatch); break; } } } } if (ans == INT_MAX){ // no min could take place as pointer didnt reach 3k cout << -1; } else{ cout << ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...