제출 #404453

#제출 시각아이디문제언어결과실행 시간메모리
404453radaiosm7JJOOII 2 (JOI20_ho_t2)C++98
100 / 100
12 ms1996 KiB
#include <bits/stdc++.h>
using namespace std;
int n, k, f, one, two, three;
vector<int> j;
vector<int> o;
vector<int> i;
char word[200005];
int ans;

int main() {
  scanf("%d%d", &n, &k);
  scanf("\n%s", word);
  f = strlen(word);
  ans = INT_MAX;

  for (f=0; f < n; ++f) {
    if (word[f] == 'J') {
      j.push_back(f);
    }

    else if (word[f] == 'O') {
      o.push_back(f);
    }

    else {
      i.push_back(f);
    }
  }

  for (one=k-1; one < (int)j.size(); ++one) {
    two = upper_bound(o.begin(), o.end(), j[one])-o.begin();

    if (two+k-1 >= (int)o.size()) {
      continue;
    }

    three = upper_bound(i.begin(), i.end(), o[two+k-1])-i.begin();

    if (three+k-1 >= (int)i.size()) {
      continue;
    }

    ans = min(ans, max(0, i[three+k-1]-j[one-k+1]+1-3*k));
  }

  if (ans == INT_MAX) {
    printf("-1\n");
  }

  else {
    printf("%d\n", ans);
  }
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("\n%s", word);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...