Submission #463586

# Submission time Handle Problem Language Result Execution time Memory
463586 2021-08-11T10:39:12 Z prvocislo Lollipop (POI11_liz) C++17
100 / 100
643 ms 31720 KB
#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 time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 8 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 488 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
3 Correct 5 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 844 KB Output is correct
2 Correct 9 ms 764 KB Output is correct
3 Correct 55 ms 1676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1736 KB Output is correct
2 Correct 173 ms 4248 KB Output is correct
3 Correct 113 ms 3080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2064 KB Output is correct
2 Correct 33 ms 2592 KB Output is correct
3 Correct 95 ms 4612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 4576 KB Output is correct
2 Correct 118 ms 5716 KB Output is correct
3 Correct 187 ms 9000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 313 ms 10168 KB Output is correct
2 Correct 289 ms 13396 KB Output is correct
3 Correct 349 ms 17556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 11576 KB Output is correct
2 Correct 373 ms 18008 KB Output is correct
3 Correct 411 ms 21856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 614 ms 22876 KB Output is correct
2 Correct 497 ms 28900 KB Output is correct
3 Correct 643 ms 29328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 632 ms 29400 KB Output is correct
2 Correct 593 ms 30224 KB Output is correct
3 Correct 432 ms 31720 KB Output is correct