Submission #649590

#TimeUsernameProblemLanguageResultExecution timeMemory
649590inwbearJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
7 ms2000 KiB
#include<bits/stdc++.h> using namespace std; int n,k,ans=INT_MAX,mid_size; char c[200005]; vector<int>pos[3]; int cur[3]; int main(){ scanf("%d %d",&n,&k); scanf("%s",c+1); //hashing the position of each character for(int i=1;i<=n;i++){ if(c[i] == 'J')pos[0].push_back(i); else if(c[i] == 'O')pos[1].push_back(i); else pos[2].push_back(i); } //brute-force for all possible x for(int i = 1; i <= n; i++){ while(cur[0] < pos[0].size()){ if(pos[0][cur[0]] >= i)break; cur[0]++; } if(cur[0]+k-1 >= pos[0].size())break; while(cur[1] < pos[1].size()){ if(pos[1][cur[1]] >= pos[0][cur[0]+k-1])break; cur[1]++; } if(cur[1]+k-1 >= pos[1].size())break; while(cur[2] < pos[2].size()){ if(pos[2][cur[2]] >= pos[1][cur[1]+k-1])break; cur[2]++; } if(cur[2]+k-1 >= pos[2].size())break; mid_size = pos[2][cur[2]+k-1] - i + 1; ans=min(ans, mid_size - (3 * k)); } if(ans==INT_MAX)printf("-1"); else printf("%d",ans); }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while(cur[0] < pos[0].size()){
      |           ~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     if(cur[0]+k-1 >= pos[0].size())break;
      |        ~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while(cur[1] < pos[1].size()){
      |           ~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if(cur[1]+k-1 >= pos[1].size())break;
      |        ~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while(cur[2] < pos[2].size()){
      |           ~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     if(cur[2]+k-1 >= pos[2].size())break;
      |        ~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d %d",&n,&k);
      |   ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%s",c+1);
      |   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...