Submission #331292

#TimeUsernameProblemLanguageResultExecution timeMemory
331292syyJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
16 ms3180 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++) #define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--) typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<ll, pi> ipi; typedef pair<pi, pi> pipi; #define f first #define s second typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<pii> vpii; #define pb push_back #define pf push_front #define all(v) v.begin(), v.end() #define size(v) (ll) v.size() #define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin()); #define INF (ll) 1e9 + 100 #define LLINF (ll) 1e18 #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge"))) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss ll n, k, ans = INF; char ch; vi J, O, I; int main() { fastio; cin >> n >> k; FOR(i, 1, n) { cin >> ch; if (ch == 'J') J.pb(i); else if (ch == 'O') O.pb(i); else I.pb(i); } FOR(i, 0, size(J)-k) { ll j = i + k - 1; ll opos = lower_bound(all(O), J[j]) - O.begin(); if (opos + k - 1 < size(O)) { ll ipos = lower_bound(all(I), O[opos + k - 1]) - I.begin(); if (ipos + k - 1 < size(I)) ans = min(ans, I[ipos + k - 1] - J[i] + 1 - 3*k); } } cout << (ans == INF ? -1 : ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...