Submission #716206

#TimeUsernameProblemLanguageResultExecution timeMemory
716206hello_there_123JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
15 ms3036 KiB
#include<bits/stdc++.h> using namespace std; #define int long long vector<int>pos[3]; main(){ int n,k; cin>>n>>k; string s; cin>>s; for(int i=1;i<=n;i++){ if(s[i-1] == 'J') pos[0].push_back(i); if(s[i-1] == 'O') pos[1].push_back(i); if(s[i-1] == 'I') pos[2].push_back(i); } int mini = 1e10; if(pos[0].size()<k-1){ cout<<"-1"; return 0; } for(int i=k-1;i<pos[0].size();i++){ int x = lower_bound(pos[1].begin(),pos[1].end(),pos[0][i])-pos[1].begin(); int x2 = pos[1][x+k-1]; if(x+k-1>=pos[1].size()){ break; } int y = lower_bound(pos[2].begin(),pos[2].end(),x2)-pos[2].begin(); if(y+k-1>=pos[2].size()){ break; } int p = pos[2][y+k-1]-pos[0][i-k+1]+1; mini = min(mini,p); } if(mini>1e9) cout<<"-1"; else cout<<mini-k*3; }

Compilation message (stderr)

ho_t2.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main(){
      | ^~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:16:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   16 |  if(pos[0].size()<k-1){
      |     ~~~~~~~~~~~~~^~~~
ho_t2.cpp:20: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]
   20 |  for(int i=k-1;i<pos[0].size();i++){
      |                ~^~~~~~~~~~~~~~
ho_t2.cpp:24:11: 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]
   24 |   if(x+k-1>=pos[1].size()){
      |      ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:29:11: 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]
   29 |   if(y+k-1>=pos[2].size()){
      |      ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...