Submission #831427

#TimeUsernameProblemLanguageResultExecution timeMemory
831427MularstyleJJOOII 2 (JOI20_ho_t2)C++14
1 / 100
1 ms232 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; char s[3008]; int qs[3008]; cin>>n>>k; cin>>s+1; n=strlen(s+1); vector<int> js; vector<int> is; for(int i = 1; i<= n; i++) { if(s[i] == 'J') js.push_back(i); else if(s[i] == 'O') qs[i] = 1; else is.push_back(i); qs[i] += qs[i-1]; } int mn = INT_MAX; int cur = 0; for(int j = k-1; j< js.size(); j++) { while(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]< k) cur++; if(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]>= k) { mn = min(mn, is[cur+k-1]-js[j-k+1]+1); } } if(mn == INT_MAX) cout<<"-1\n"; else cout<<mn-3*k; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:11:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   11 |  cin>>s+1;
      |       ~^~
ho_t2.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for(int j = k-1; j<  js.size(); j++)
      |                   ~^~~~~~~~~~~~
ho_t2.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   while(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]< k)
      |         ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:33:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   if(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]>= k)
      |      ~~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...