답안 #1101824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101824 2024-10-16T23:53:10 Z BlueGlaucus1 JJOOII 2 (JOI20_ho_t2) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int n; 
int binarysearch(int target, int low, vector<int> &arr) {
    int high = n;
    int val = -1;
    int mid;
    while (low <= high) {
        mid = (low + high) / 2;
        if (arr[mid] >= val) {
            working = mid;
            high = mid - 1;
        } 
        else if (arr[mid] < target) {
            low = mid + 1;
        }
    }
    return val;
}
 
int main() {
    string s;
    int k;
    cin >> n;
    cin >> k;
    cin >> s;
 
    vector<int> prefixj = {0};
    vector<int> prefixo = {0};
    vector<int> prefixi = {0};
 
    int jCount = 0;
    int oCount = 0;
    int iCount = 0;
    for (auto p: s) {
        if (p == 'J') {
            jCount++;
        }
        else if (p == 'O') {
            oCount++;
        }
        else if (p == 'I') {
            iCount++;
        }
        prefixj.push_back(jCount);
        prefixo.push_back(oCount);
        prefixi.push_back(iCount); 
    }
    int answer = 200001;
 
    for (int i = 1; i <=n; i++) {
        int position_of_j = find(prefixj[i - 1] + k, i, prefixj);
        if (position_of_j == -1) {
            break;
        }
        int position_of_o = find(prefixo[jPos] + k, position_of_j, prefixo);
        if (position_of_o == -1) {
            break;
        }
        int position_of_i = find(prefixi[oPos] + k, position_of_o, prefixi);
        if (position_of_i == -1) {
            break;
        }
        answer = min(answer, position_of_i - i - 3 * k + 1);
    }
    if (answer == 200001) {
        answer = -1;
    }
    cout << answer;
}

Compilation message

ho_t2.cpp: In function 'int binarysearch(int, int, std::vector<int>&)':
ho_t2.cpp:14:13: error: 'working' was not declared in this scope
   14 |             working = mid;
      |             ^~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:55:64: error: no matching function for call to 'find(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type, int&, std::vector<int>&)'
   55 |         int position_of_j = find(prefixj[i - 1] + k, i, prefixj);
      |                                                                ^
In file included from /usr/include/c++/10/bits/locale_facets.h:48,
                 from /usr/include/c++/10/bits/basic_ios.h:37,
                 from /usr/include/c++/10/ios:44,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from ho_t2.cpp:1:
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)'
  422 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note:   template argument deduction/substitution failed:
ho_t2.cpp:55:64: note:   mismatched types 'std::istreambuf_iterator<_CharT>' and 'int'
   55 |         int position_of_j = find(prefixj[i - 1] + k, i, prefixj);
      |                                                                ^
ho_t2.cpp:59:42: error: 'jPos' was not declared in this scope
   59 |         int position_of_o = find(prefixo[jPos] + k, position_of_j, prefixo);
      |                                          ^~~~
ho_t2.cpp:63:42: error: 'oPos' was not declared in this scope
   63 |         int position_of_i = find(prefixi[oPos] + k, position_of_o, prefixi);
      |                                          ^~~~