QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252164 | #7713. Rikka with Mutex | SolitaryDream# | AC ✓ | 86ms | 3688kb | C++17 | 961b | 2023-11-15 16:07:38 | 2023-11-15 16:07:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool Check(const string &s, int num) {
int n = s.size();
for (int i = 0, j, curE = 0; i < n; i = j + 1) {
j = i;
int delta = 0;
while (j < n) {
delta += (s[j] == 'V' ? 1 : -1);
if (delta == 1) break;
if (curE + delta < 0) return 0;
++j;
}
if (j == n) return 1;
curE += delta * num;
}
return 1;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int Case;
cin >> Case;
while (Case--) {
string s;
cin >> s;
if (s[0] == 'P') { cout << -1 << '\n'; continue; }
int ans = -1;
for (int l = 1, r = s.size(); l <= r; ) {
int mid = (l + r) >> 1;
if (Check(s, mid)) ans = mid, r = mid - 1; else l = mid + 1;
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3364kb
input:
4 VPP VPPVVVVPPPPPPPP VPPPPPPPPPPPPPP P
output:
2 3 14 -1
result:
ok 4 number(s): "2 3 14 -1"
Test #2:
score: 0
Accepted
time: 86ms
memory: 3688kb
input:
1000 VPPVVVPPPPPVVVVVVPPPPPPPPPPVVVVVVVVVVVPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV...
output:
46 335 50 339 470 745 105 71 351 200 51031 93945 82501 99158 94960 87620 86384 80421 73576 92033 52670 30885 79876 5 72163 26055 82086 3 62572 31654 555 46 3 35 196 248 748 558 101 18 885 902 1 3 571 6 429 2 898 911 278 670 187 258 379 2 583 1 869 1 752 173 766 862 891 852 157 330 4 614 711 4 202 19...
result:
ok 1000 numbers