Submission #486189

#TimeUsernameProblemLanguageResultExecution timeMemory
486189Sho10JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
9 ms5476 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho #define ll long long #define double long double #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define aint(a) (a).begin(), (a).end() #define f first #define s second #define pb push_back #define mp make_pair #define pi pair #define rc(s) return cout<<s,0 #define endl '\n' #define mod 998244353 #define PI 3.14159265359 #define INF 1000000005 #define LINF 1000000000000000005ll #define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ll n,k,pref[4][200005]; string s; int32_t main(){ CODE_START; cin>>n>>k; cin>>s; for(ll i=0;i<s.size();i++) { pref[0][i+1]=pref[0][i]; pref[1][i+1]=pref[1][i]; pref[2][i+1]=pref[2][i]; if(s[i]=='J'){ pref[0][i+1]++; }else if(s[i]=='O'){ pref[1][i+1]++; }else { pref[2][i+1]++; } } ll ans=LINF,i=1,j=1,pos=1; for(ll l=1;l<=n;l++) { while(i<=n&&pref[0][i]-pref[0][l-1]<k){ i++; } while(j<=n&&pref[1][j]-pref[1][i-1]<k){ j++; } while(pos<=n&&pref[2][pos]-pref[2][j-1]<k){ pos++; } if(i<=n&&j<=n&&pos<=n){ ans=min(ans,pos-l+1); } } if(ans==LINF){ ans=3*k-1; } ans-=3*k; cout<<ans<<endl; }

Compilation message (stderr)

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:26:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 | for(ll i=0;i<s.size();i++)
      |            ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...