Submission #245781

# Submission time Handle Problem Language Result Execution time Memory
245781 2020-07-07T11:44:50 Z Atill83 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
20 ms 2084 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, k;
string s;

vector<int> j, o, I;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>n>>k;
    int ans = mod;
    cin>>s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'J') j.push_back(i);
        else if(s[i] == 'O') o.push_back(i);
        else I.push_back(i);
    }
    for(int i = 0; i <= (int) o.size() - k; i++){
        int i1 = upper_bound(j.begin(), j.end(), o[i]) - j.begin() - 1;
        int i2 = upper_bound(I.begin(), I.end(), o[i + k - 1]) - I.begin();
        if(i1 < k - 1 || i2 > (int) I.size() - k) continue;
        int sim = (j[i1] - j[i1 - k + 1] + 1 - k);
        sim += o[i] - j[i1] - 1;
        sim += o[i + k - 1] - o[i] + 1 - k;
        sim += I[i2] - o[i + k - 1] - 1;
        sim += I[i2 + k - 1] - I[i2] + 1 - k;
        //cout<<sim<<endl;
        ans = min(ans, sim);
    }
    

    if(ans == mod)
        ans = -1;
    cout<<ans<<endl;
    

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 392 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 392 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 14 ms 1540 KB Output is correct
37 Correct 15 ms 1864 KB Output is correct
38 Correct 15 ms 2036 KB Output is correct
39 Correct 15 ms 2052 KB Output is correct
40 Correct 13 ms 2020 KB Output is correct
41 Correct 15 ms 2036 KB Output is correct
42 Correct 20 ms 1924 KB Output is correct
43 Correct 11 ms 1376 KB Output is correct
44 Correct 11 ms 1524 KB Output is correct
45 Correct 13 ms 2052 KB Output is correct
46 Correct 13 ms 1920 KB Output is correct
47 Correct 14 ms 2052 KB Output is correct
48 Correct 13 ms 2052 KB Output is correct
49 Correct 10 ms 1292 KB Output is correct
50 Correct 13 ms 1924 KB Output is correct
51 Correct 14 ms 1924 KB Output is correct
52 Correct 8 ms 1608 KB Output is correct
53 Correct 9 ms 1864 KB Output is correct
54 Correct 10 ms 2084 KB Output is correct
55 Correct 8 ms 2052 KB Output is correct
56 Correct 7 ms 2052 KB Output is correct