Submission #227175

#TimeUsernameProblemLanguageResultExecution timeMemory
227175ho94949JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
29 ms3200 KiB
#include <bits/stdc++.h> using namespace std; int N, K; char s[202020]; int js[202020], os[202020], is[202020]; int main() { scanf("%d%d", &N, &K); scanf("%s", s+1); for(int i=1; i<=N; ++i) { js[i] = js[i-1], os[i] = os[i-1], is[i] = is[i-1]; if(s[i] == 'J') ++js[i]; if(s[i] == 'O') ++os[i]; if(s[i] == 'I') ++is[i]; } int ans = -1; for(int i=0; i<N; ++i) { int np = i; int jp = lower_bound(js+np, js+N+1, js[np]+K) - js; if(jp == N+1) break; int op = lower_bound(os+jp, os+N+1, os[jp]+K) - os; if(op == N+1) break; int ip = lower_bound(is+op, is+N+1, is[op]+K) - is; if(ip == N+1) break; if(ans == -1) ans = ip-np-3*K; else ans = min(ans, ip-np-3*K); } printf("%d\n", ans); }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &K);
     ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", s+1);
     ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...