Submission #463586

#TimeUsernameProblemLanguageResultExecution timeMemory
463586prvocisloLollipop (POI11_liz)C++17
100 / 100
643 ms31720 KiB
#include <iostream> #include <vector> #include <string> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; string s; cin >> s; vector<int> v(n+1), nx1(n+1, n+1), pf(n+1); for (int i = 1; i <= n; i++) { pf[i] = v[i] = (s[i - 1] == 'W' ? 1 : 2); pf[i] += pf[i - 1]; } for (int i = n; i > 0; i--) { if (v[i] == 1) nx1[i] = i; else if (i != n) nx1[i] = nx1[i + 1]; } while (m--) { int k; cin >> k; int len = lower_bound(pf.begin(), pf.end(), k) - pf.begin(); if (len == n+1) cout << "NIE\n"; else if (pf[len] == k) cout << 1 << " " << len << "\n"; else // k+1 { int mv = min(nx1[1], nx1[len] - len + 1); int l = mv, r = mv + len - 1; if (r > n) cout << "NIE\n"; else if (pf[r] - pf[l - 1] == k) cout << l << " " << r << "\n"; else cout << l + 1 << " " << r << "\n"; } } return 0; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...