Submission #747678

# Submission time Handle Problem Language Result Execution time Memory
747678 2023-05-24T13:09:13 Z Sami_Massah JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;


const long long maxn = 3e3 + 12, mod = 1e9 + 7, inf = 1e9 + 12 ;
long long n, k;
string s;
int main(){
    cin >> n >> k;
    cin >> s;
    int l, r;
    int cnt = 0;
    for(int i = n - 1; cnt < k && i >= 0; i--)
        if(s[i] == 'I'){
            cnt += 1;
            r = i;
            }
    cnt = 0;
    for(int i = 0; i < n && cnt < k; i++)
        if(s[i] == 'J'){
            cnt += 1;
            l = i;
        }
    cnt = 0;

    for(int i = l + 1; i < r; i++)
        if(s[i] == 'O')
            cnt += 1;

    if(cnt != k){
        cout << -1 << endl;
        return 0;
    }

    l = -1;
    r = -1;
    for(int i = 0; i < n && l == -1; i++)
        if(s[i] == 'J')
            l = i;
    for(int i = n - 1; i >= 0 && r == -1; i--)
        if(s[i] == 'I')
            r = i;
    cout << r - l + 1 - (k * 3) << endl;

}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:26:13: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |     for(int i = l + 1; i < r; i++)
      |             ^
ho_t2.cpp:26:26: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |     for(int i = l + 1; i < r; i++)
      |                        ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -