Submission #364836

# Submission time Handle Problem Language Result Execution time Memory
364836 2021-02-10T08:41:16 Z cpp219 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
19 ms 2228 KB
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 3;
const ll inf = 1e9 + 7;
typedef pair<int,int> LL;
string s;
ll n,k;
vector<ll> J,O,I;

ll Forwardk(ll pos,vector<ll> &v){
    ll now = lower_bound(v.begin(),v.end(),pos) - v.begin();
    now += k - 1;
    if (now < v.size()) return v[now];
    return -1;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n>>k>>s; s = " " + s;
    for (ll i = 1;i <= n;i++){
        if (s[i] == 'J') J.push_back(i);
        if (s[i] == 'O') O.push_back(i);
        if (s[i] == 'I') I.push_back(i);
    }
    ll ans = inf;
    for (ll i = 1;i <= n;i++){
        if (s[i] != 'J') continue;
        ll p = Forwardk(i,J); if (p == -1) break;
        p = Forwardk(p,O); if (p == -1) break;
        p = Forwardk(p,I); if (p == -1) break;
        ans = min(ans,p - i + 1 - 3*k);
    }
    cout<<(ans == inf ? -1 : ans);
}

Compilation message

ho_t2.cpp: In function 'int Forwardk(int, std::vector<int>&)':
ho_t2.cpp:17:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     if (now < v.size()) return v[now];
      |         ~~~~^~~~~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 372 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 372 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 0 ms 364 KB Output is correct
36 Correct 15 ms 1472 KB Output is correct
37 Correct 17 ms 1844 KB Output is correct
38 Correct 19 ms 2096 KB Output is correct
39 Correct 16 ms 1972 KB Output is correct
40 Correct 7 ms 2092 KB Output is correct
41 Correct 12 ms 2092 KB Output is correct
42 Correct 16 ms 2100 KB Output is correct
43 Correct 3 ms 1388 KB Output is correct
44 Correct 4 ms 1504 KB Output is correct
45 Correct 5 ms 2228 KB Output is correct
46 Correct 5 ms 2092 KB Output is correct
47 Correct 5 ms 2092 KB Output is correct
48 Correct 5 ms 1992 KB Output is correct
49 Correct 4 ms 1524 KB Output is correct
50 Correct 6 ms 2224 KB Output is correct
51 Correct 5 ms 2092 KB Output is correct
52 Correct 4 ms 1724 KB Output is correct
53 Correct 5 ms 2096 KB Output is correct
54 Correct 11 ms 1972 KB Output is correct
55 Correct 5 ms 1972 KB Output is correct
56 Correct 3 ms 1972 KB Output is correct