답안 #364997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364997 2021-02-10T17:35:01 Z Dymo JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
12 ms 3312 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
//#define endl "\n"
const ll maxn =1e4+10;
const ll mod=1e9+7;
const ll base=1e18;

vector<ll> vt;
vector<ll> vt1;
vector<ll> vt2;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
     ll n, k;
     cin>> n>> k;
    string s;
    cin>> s;
    ll cnt=0;
    for (auto to:s)
    {
        cnt++;
        if (to=='J')
        {
           vt.pb(cnt);
        }
        else if (to=='O')
        {
           vt1.pb(cnt);
        }
        else
        {
           vt2.pb(cnt);
        }
    }
    ll ans=base;
    for (int i=0;i+k-1<vt.size();i++)
    {
       ll st=vt[i];
       ll nxt=vt[i+k-1]+1;
    //   cout <<st<<" "<<nxt<<endl;
       auto h=lower_bound(vt1.begin(),vt1.end(),nxt)-vt1.begin();
    //   cout <<vt1[h]<<" "<<h<<endl;
       if (h+k-1>=vt1.size()) continue;
      // cout <<"WTF"<<endl;
       nxt=vt1[h+k-1]+1;
       h=lower_bound(vt2.begin(),vt2.end(),nxt)-vt2.begin();
       if (h+k-1>=vt2.size()) continue;
       ll ed=vt2[h+k-1];
        ans=min(ans,ed-st+1-3*k);
    }
    if (ans==base) ans=-1;
    cout <<ans<<endl;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:49:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i=0;i+k-1<vt.size();i++)
      |                  ~~~~~^~~~~~~~~~
ho_t2.cpp:56:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |        if (h+k-1>=vt1.size()) continue;
      |            ~~~~~^~~~~~~~~~~~
ho_t2.cpp:60:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |        if (h+k-1>=vt2.size()) continue;
      |            ~~~~~^~~~~~~~~~~~
ho_t2.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   25 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 392 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 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 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 364 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 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 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 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 392 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 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 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 364 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 1 ms 364 KB Output is correct
36 Correct 10 ms 2396 KB Output is correct
37 Correct 12 ms 2916 KB Output is correct
38 Correct 12 ms 2892 KB Output is correct
39 Correct 11 ms 3000 KB Output is correct
40 Correct 9 ms 3044 KB Output is correct
41 Correct 10 ms 3044 KB Output is correct
42 Correct 11 ms 2916 KB Output is correct
43 Correct 6 ms 1984 KB Output is correct
44 Correct 7 ms 2152 KB Output is correct
45 Correct 11 ms 2984 KB Output is correct
46 Correct 8 ms 2984 KB Output is correct
47 Correct 8 ms 3044 KB Output is correct
48 Correct 8 ms 3016 KB Output is correct
49 Correct 6 ms 1892 KB Output is correct
50 Correct 8 ms 3016 KB Output is correct
51 Correct 11 ms 3044 KB Output is correct
52 Correct 5 ms 2520 KB Output is correct
53 Correct 6 ms 2912 KB Output is correct
54 Correct 9 ms 3312 KB Output is correct
55 Correct 5 ms 3312 KB Output is correct
56 Correct 4 ms 3312 KB Output is correct