| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1340098 | asim | Tornjevi (COCI25_tornjevi) | C++20 | 1096 ms | 1916 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(v) v.begin(), v.end()
void solve() {
int n, q; cin >> n >> q;
string s; cin >> s;
int pref[n + 1];
pref[0] = 0;
for(int i = 1; i <= n; i++) {
pref[i] = pref[i - 1] + (s[i - 1] == 'P' ? 1 : 0);
}
while(q--) {
int l, r; cin >> l >> r;
int a = pref[r] - pref[l - 1], b = r - l + 1 - a;
l--, r--;
string g = s;
if(a == r - l + 1 or !a) {
cout << r - l + 1 << '\n';
continue;
}
int cnt = 0;
while(true) {
char c;
bool ok = false;
for(int i = r; i >= l; i--) {
if(!ok) {
if(g[i] != 'X') {
c = g[i];
if(c == 'P')a--;
else b--;
g[i] = 'X';
ok = true;
}
}
else {
if(g[i] != 'X') {
if(c != g[i]) {
c = g[i];
if(c == 'P')a--;
else b--;
g[i] = 'X';
}
}
}
}
if(!ok)break;
cnt++;
if(a == 0 or b == 0) {
cnt += a + b;
break;
}
}
cout << cnt << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
//cin >> T;
while (T--) solve();
}| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
