# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1023759 | vjudge1 | JJOOII 2 (JOI20_ho_t2) | C++17 | 580 ms | 436 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>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast")
#define pii pair <int, int>
#define pb push_back
#define pp pop_back
#define int int64_t
#define sc second
#define fr first
using namespace std;
const int T=1e9+7;
signed main() {
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int n, k, i, j, a, J, O, I, t, mn=T, x, y;
string s;
bool r, q;
cin >> n >> k >> s;
a=(1<<n);
for (j=1; j<a; j++) {
r=1, q=1, x=0, y=0;
bitset <2024> b(j);
vector <char> v;
for (i=0; i<min(a, n); i++) {
if (b[i]==1) {
v.pb(s[i]);
if (q) x=i, q=0;
else y=i;
}
}
if (int(v.size())!=k*3) continue;
for (i=0; i<k; i++) {
if (v[i]!='J') {
r=0;
break;
}
}
for (i=k; i<2*k; i++) {
if (v[i]!='O') {
r=0;
break;
}
}
for (i=2*k; i<3*k; i++) {
if (v[i]!='I') {
r=0;
break;
}
}
// for (auto j: v) {
// cout << j;
// }
// cout << '\n';
// cout << x << ' ' << y << '\n';
if (r) mn=min(y-x-k*3+1, mn);
}
if (mn==T) cout << -1;
else cout << mn;
}
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... |