Submission #857127

#TimeUsernameProblemLanguageResultExecution timeMemory
857127SUNWOOOOOOOOJOI 문장 (JOI14_ho_t1)C++17
0 / 100
1 ms344 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...