# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
982655 | SmuggingSpun | JJOOII 2 (JOI20_ho_t2) | C++14 | 178 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
int n, k;
string s;
namespace sub1{
void solve(){
int m = 1 << n, ans = INT_MAX;
string pat = string(k, 'J') + string(k, 'O') + string(k, 'I');
for(int mask = 0; mask < m; mask++){
string current = "";
for(int i = 0; i < n; i++){
if(1 << i & mask){
current += s[i];
}
}
if(current == pat){
int l = 0, r = n - 1;
while((1 << l & mask) == 0){
l++;
}
while((1 << r & mask) == 0){
r--;
}
int cnt = 0;
for(int i = l; i <= r; i++){
if((1 << i & mask) == 0){
cnt++;
}
}
minimize(ans, cnt);
}
}
cout << (ans == INT_MAX ? -1 : ans);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> k >> s;
if(n <= 21){
sub1::solve();
}
}
Compilation message (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... |