Submission #286885

#TimeUsernameProblemLanguageResultExecution timeMemory
286885arnold518JJOOII 2 (JOI20_ho_t2)C++14
100 / 100
8 ms2688 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; int N, K; char S[MAXN+10]; int P[MAXN+10], Q[MAXN+10]; int main() { scanf("%d%d", &N, &K); scanf("%s", S+1); vector<int> V; P[0]=-1; for(int i=1; i<=N; i++) { if(S[i]=='J') V.push_back(i); if(V.size()<K) P[i]=-1; else P[i]=V[V.size()-K]; } V.clear(); Q[N+1]=-1; for(int i=N; i>=1; i--) { if(S[i]=='I') V.push_back(i); if(V.size()<K) Q[i]=-1; else Q[i]=V[V.size()-K]; } V.clear(); int ans=2e9; for(int i=1; i<=N; i++) { if(S[i]=='O') V.push_back(i); if(V.size()<K) continue; else { int p=V[V.size()-K], q=i; int l=P[p-1], r=Q[q+1]; if(l==-1 || r==-1) continue; ans=min(ans, r-l+1); } } if(ans==2e9) return !printf("-1\n"); printf("%d\n", ans-3*K); }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:24:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |   if(V.size()<K) P[i]=-1;
      |      ~~~~~~~~^~
ho_t2.cpp:33:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |   if(V.size()<K) Q[i]=-1;
      |      ~~~~~~~~^~
ho_t2.cpp:42:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |   if(V.size()<K) continue;
      |      ~~~~~~~~^~
ho_t2.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%s", S+1);
      |  ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...