This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
#else
#define debug(args...)
#endif
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 200005
char key[] = {'J', 'O', 'I'};
int n, k;
char s[MAXN];
deque<int> dq[100];
int nxt[100][MAXN];
int ctoi(char c) {
REP (i, 0, 3) {
if (key[i] == c) return i;
}
assert(0);
}
int main() {
scanf("%d%d", &n, &k);
scanf(" %s", s);
REP (i, 0, n + 1) {
REP (j, 0, 3) {
nxt[j][i] = n;
}
}
REP (i, 0, n) {
int c = ctoi(s[i]);
dq[c].pb(i);
if (dq[c].size() >= k) {
nxt[c][dq[c].front()] = i;
dq[c].pop_front();
}
}
REP (j, 0, 3) {
RREP (i, n - 1, 0) {
mnto(nxt[j][i], nxt[j][i + 1]);
debug("%c %d: %d\n", key[j], i, nxt[j][i]);
}
}
int ans = INF;
REP (i, 0, n) {
int r = nxt[2][nxt[1][nxt[0][i]]];
if (r != n) {
mnto(ans, r - i + 1 - k * 3);
}
}
if (ans == INF) {
printf("-1\n");
} else {
printf("%d\n", ans);
}
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:67:20: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
67 | if (dq[c].size() >= k) {
| ~~~~~~~~~~~~~^~~~
ho_t2.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf(" %s", s);
| ~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |