Submission #771969

# Submission time Handle Problem Language Result Execution time Memory
771969 2023-07-03T12:59:19 Z Trisanu_Das JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
using namespace std;
//limit definitions
#define N 202020

int n, k;
char s[N];
int js[N], os[N], is[N];

signed main() {
    cin >> n >> k >> s;
    for(int i = 1; i <= n; ++i) {
        js[i] = js[i-1], os[i] = os[i - 1], is[i] = is[i - 1];
        if(s[i] == 'J') ++js[i];
        if(s[i] == 'O') ++os[i];
        if(s[i] == 'I') ++is[i];
    }
    int ans = -1;
    for(int i = 0; i < n; ++i) {
        int np = i;
        int jp = lower_bound(js+np, js+N+1, js[np]+k) - js;
        if(jp == n+1) break; 
        int op = lower_bound(os+jp, os+N+1, os[jp]+k) - os;
        if(op == n+1) break; 
        int ip = lower_bound(is+op, is+N+1, is[op]+k) - is;
        if(ip == n+1) break;
        if(ans == -1) ans = ip-np-3*k;
        else ans = min(ans, ip-np-3*k);
    }
    cout << ans << '\n';
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:27:29: warning: array subscript 202021 is outside array bounds of 'long long int [202020]' [-Warray-bounds]
   27 |         int jp = lower_bound(js+np, js+N+1, js[np]+k) - js;
      |                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:14:5: note: while referencing 'js'
   14 | int js[N], os[N], is[N];
      |     ^~
ho_t2.cpp:29:29: warning: array subscript 202021 is outside array bounds of 'long long int [202020]' [-Warray-bounds]
   29 |         int op = lower_bound(os+jp, os+N+1, os[jp]+k) - os;
      |                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:14:12: note: while referencing 'os'
   14 | int js[N], os[N], is[N];
      |            ^~
ho_t2.cpp:31:29: warning: array subscript 202021 is outside array bounds of 'long long int [202020]' [-Warray-bounds]
   31 |         int ip = lower_bound(is+op, is+N+1, is[op]+k) - is;
      |                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:14:19: note: while referencing 'is'
   14 | int js[N], os[N], is[N];
      |                   ^~
# 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 -