Submission #857127

# Submission time Handle Problem Language Result Execution time Memory
857127 2023-10-05T12:05:19 Z SUNWOOOOOOOO None (JOI14_ho_t1) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1000005;
int n;
string str;

bool check(int x)
{
    int j = 0, lastI;
    for (int i = n - 1; i >= 0; i--){
        if (str[i] == 'I' && j < x) {
            lastI = i, j++;
        }
    }
    if (j < x) return false;

    int ret = 0, IJcnt = 0;
    for (int i = 0; i < n; i++){
        if (str[i] == 'J' || (str[i] == 'I' && i < lastI)) IJcnt++;
        if (str[i] == 'O' && IJcnt) {ret++, IJcnt--;}
    }
    return ret >= x;
}

int main()
{
    cin >> n >> str;
    int low = 0, high = n / 3, mid, ans = 0;
    while (low <= high){
        mid = (low + high) / 2;
        if (check(mid)) {
            ans = mid;
            low = mid + 1;
        }
        else high = mid - 1;
    }

    printf("%d\n", ans);

    return 0;
}

Compilation message

2014_ho_t1.cpp: In function 'bool check(int)':
2014_ho_t1.cpp:19:45: warning: 'lastI' may be used uninitialized in this function [-Wmaybe-uninitialized]
   19 |         if (str[i] == 'J' || (str[i] == 'I' && i < lastI)) IJcnt++;
      |                              ~~~~~~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -