Submission #516442

#TimeUsernameProblemLanguageResultExecution timeMemory
516442shivensinha4Take-out (POI13_usu)C++17
22 / 100
39 ms65540 KiB
#include "bits/stdc++.h" #ifdef mlocal #include "./Competitive-Code-Library/snippets/prettyprint.h" #endif using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef array<int, 2> ii; //#define endl '\n' int main() { #ifdef mlocal freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; string s; cin >> s; vi pref(n); vector<deque<int>> prefpos(3*n); for_(i, 0, n) { if (s[i] == 'c') pref[i] = -k; else pref[i] = 1; if (i) pref[i] += pref[i-1]; prefpos[pref[i]+n].push_back(i); } function<void(int, int)> solve = [&] (int l, int r) { if (l > r) return; // cout << "solving " << l << " " << r << endl; int prepref = (l > 0 ? pref[l-1] : 0); // cout << "\tgot previous prefix: " << prepref << endl; assert(pref[r] == prepref); while (prefpos[prepref+n].size() and prefpos[prepref+n].front() < l) prefpos[prepref+n].pop_front(); // cout << "\ttaking from " << prefpos[prepref+n].size() << endl; int firstpos = prefpos[prepref+n].front(); /*if (l == 1 and r == 6) { // cout << "\tprefix sum: " << prepref << " is remaining at positions: " << prefpos[prepref+n] << endl; // return; }*/ assert(firstpos <= r); if (firstpos != r) { // cout << "\tyep splitting " << firstpos << endl; solve(l, firstpos); solve(firstpos+1, r); return; } prefpos[prepref+n].pop_front(); for_(opt, 0, k+2) { int va = (l+opt-1 >= 0 ? pref[l+opt-1] : 0) - (l > 0 ? pref[l-1] : 0); int sufopt = k+1-opt; int vb = pref[r] - (r-sufopt >= 0 ? pref[r-sufopt] : 0); if (va+vb == 0) { vi ans; for_(i, l, l+opt) ans.push_back(i); for_(i, r-sufopt+1, r+1) ans.push_back(i); for (auto i: ans) cout << i+1 << " "; cout << endl; // cout << "should have gone to " << l+opt << " " << r-sufopt << " from " << l << " " << r << endl; solve(l+opt, r-sufopt); return; } } // cout << "uhhh found nothing " << l << " " << r << endl; assert(false); }; solve(0, n-1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...