QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84033 | #5647. Another Wine Tasting Event | Bervig | WA | 54ms | 91060kb | C++14 | 1.6kb | 2023-03-05 03:54:03 | 2023-03-05 03:54:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string a;
cin >> a;
a = " " + a;
vector<int> sum(2*n+2, 0);
for(int i = 1; i <= n; i++) {
sum[i] = sum[i-1] + (a[i] == 'W');
}
vector<int> gap_left(2*n+2, 0), gap_right(2*n+2, 0);
int prev = 0;
for(int i = 1; i <= 2*n-1; i++) {
gap_left[i] = i-prev;
if(a[i] == 'W') prev = i;
}
prev = 2*n;
for(int i = 2*n-1; i >= 1; i--) {
gap_right[i] = prev - i;
if(a[i] == 'W') prev = i;
}
vector<pair<long long,long long>> max_gap_left(2*n+1, {0, 0});
for(int i = 1; i <= 2*n-1; i++) {
if(gap_left[i] >= max_gap_left[i-1].first) {
max_gap_left[i] = {gap_left[i], i};
} else {
max_gap_left[i] = max_gap_left[i-1];
}
}
vector<pair<long long,long long>> max_gap_right(2*n+1, {0, 0});
for(int i = 2*n-1; i >= 1; i--) {
if(gap_right[i] >= max_gap_right[i+1].first) {
max_gap_right[i] = {gap_right[i], i};
} else {
max_gap_right[i] = max_gap_right[i+1];
}
}
int l = 0, r = 0;
long long ans = 0;
map<int,int> occ;
while(r <= 2*n-1) {
r++;
while(r <= 2*n-1 && a[r] != 'W') r++;
l = r;
if(r > 2*n-1) break;
while(r + 1 <= 2*n-1 && a[r+1] == 'W') r++;
occ[1] += r-l+1;
if(occ[1] >= n) {
cout << "1\n";
return;
}
occ[r-l+1] += gap_left[l] * gap_right[r];
if(occ[r-l+1] >= n) {
cout << r-l+1 << "\n";
return;
}
}
cout << ans << "\n";
/* cout << "sum:\n";
for(int i = 1; i <= 2*n-1; i++) {
cout << sum[i];
} cout << "\n\n"; */
}
int main() {
solve();
ios_base::sync_with_stdio(false);
cin.tie(0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3380kb
input:
5 RWWRRRWWW
output:
2
result:
ok At least n intervals
Test #2:
score: 0
Accepted
time: 2ms
memory: 3372kb
input:
1 R
output:
0
result:
ok At least n intervals
Test #3:
score: -100
Wrong Answer
time: 54ms
memory: 91060kb
input:
1000000 WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW...
output:
1
result:
wrong answer Not enough intervals