Submission #207910

#TimeUsernameProblemLanguageResultExecution timeMemory
207910BlerarghJJOOII 2 (JOI20_ho_t2)C++17
1 / 100
5 ms380 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> ii; typedef pair<ld,ld> id; #define FOR(i, a, b) for(int i=(a); i<=(b); i++) #define ROF(i, a, b) for(int i=(a); i>=(b); i--) #define MEM(x, v) memset(x, v, sizeof(x)) #define SORT(x) sort((x).begin(), (x).end()) #define CMPSORT(x, cp) sort((x).begin(), (x).end(), cp) #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define getchar_unlocked _getchar_nolock #define f first #define s second #define ins insert #define e emplace #define eb emplace_back #define ef emplace_front #define p push #define pf push_front #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define ft front #define bk back #define pp pop #define ppb pop_back #define ppf pop_front #define db cout<<"YEET\n"; #define ct(x) cout<<x<<'\n'; const ll MOD = 1e9+7; //998244353 const ll MX = 2e5+5; const ll INF = 1e18; const ld PI = acos((ld)-1); int main(){ FAST ll n, k; string ss = ""; deque<ll> idj, ido, idi, idj1; cin >> n >> k; FOR(i, 1, n){ char c; cin >> c; ss+=c; if (c == 'J') idj.pb(i); if (c == 'I') idi.pb(i); } ll op = INF; FOR(i, 1, n){ if ((ido.empty() || (ll)idj.ft() < (ll)ido.ft()) && !idj.empty() && idj.ft() < i) idj1.pb(idj.ft()), idj.ppf(); while ((ll)idj1.size()>k) idj1.ppf(); while (!idi.empty() && i > (ll)idi.ft()) idi.ppf(); if (ss[i-1] == 'O'){ ido.pb(i); if ((ll)ido.size()==k){ ido.ppf(); if ((ll)idj1.size()>=k && (ll)idi.size()>=k) { ll ops = idi[k-1] - idj1.ft()+1; ops -= k*3; op = min(op, ops); } } } } if (op == INF) cout << "-1"; else cout << op; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...