이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
const ll INF=3e18;
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
ll n,k;
string s;
vector<ll> pos[3];
signed main()
{
MottoHayaku
cin>>n>>k>>s;
rep(i,n)
{
if(s[i]=='J') pos[0].pb(i);
else if(s[i]=='O') pos[1].pb(i);
else pos[2].pb(i);
}
ll ans=INF;
rep(i,(ll)pos[0].size()-k+1)
{
ll cur=pos[0][i+k-1];
ll tmp=lower_bound(pos[1].begin(),pos[1].end(),cur)-pos[1].begin();
if(tmp+k-1>=pos[1].size()) break;
cur=pos[1][tmp+k-1];
tmp=lower_bound(pos[2].begin(),pos[2].end(),cur)-pos[2].begin();
if(tmp+k-1>=pos[2].size()) break;
ans=min(ans,pos[2][tmp+k-1]-pos[0][i]+1-3*k);
}
if(ans==INF) cout<<"-1\n";
else cout<<ans<<"\n";
}
컴파일 시 표준 에러 (stderr) 메시지
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:37:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if(tmp+k-1>=pos[1].size()) break;
| ~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:40:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(tmp+k-1>=pos[2].size()) break;
| ~~~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |