Submission #889955

#TimeUsernameProblemLanguageResultExecution timeMemory
889955avighnaJJOOII 2 (JOI20_ho_t2)C++17
13 / 100
2047 ms860 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, k;
  string s;
  cin >> n >> k >> s;

  string target = string(k, 'J') + string(k, 'O') + string(k, 'I');

  ll ans = LLONG_MAX;

  for (ll j = 0; j < n; ++j) {
    ll ptr = 0;
    ll mn = LLONG_MAX, mx = LLONG_MIN;
    for (ll i = j; i < n; ++i) {
      if (s[i] == target[ptr]) {
        mn = min(mn, i);
        mx = max(mx, i);
        ptr++;
      }
    }

    if (ptr == target.length()) {
      ans = min(ans, mx - mn + 1 - 3 * k);
    }
  }

  if (ans == LLONG_MAX) {
    cout << "-1\n";
  } else {
    cout << ans << "\n";
  }
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:30:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     if (ptr == target.length()) {
      |         ~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...