QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153402 | #5647. Another Wine Tasting Event | abzcodes | TL | 1ms | 3628kb | C++17 | 1.4kb | 2023-08-30 00:24:57 | 2023-08-30 00:24:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define ins insert
const int mxN = 1e6 + 1;
int whites[2*mxN];
void solve() {
int n; cin >> n;
string S; cin >> S;
for (int i = 0; i < 2*n - 1; i++) {
if (i > 0) whites[i] = whites[i - 1];
whites[i] += S[i] == 'W';
}
auto check = [&](int w) -> bool {
long long count = 0;
for (int i = 0; i < 2*n - 1; i++) {
int v = whites[i];
auto llidx = ub(whites + i, whites+2*n-1, v) - whites;
auto ll = llidx - i;
if (S[i] != 'W') {
ll++;
} else ll = 1;
int nxtIDX = llidx - (S[i] == 'W');
int need = v + w - (S[i] == 'W');
auto rr = ub(whites + nxtIDX, whites+2*n-1, need);
auto rrl = lb(whites + nxtIDX, whites+2*n-1, need);
long long diff = rr - rrl;
if (diff == 0) {i = llidx - (S[i] == 'W');continue;}
count += ll*1LL*diff;
if (count >= n) return true;
i = nxtIDX;
}
return false;
};
int ans = 0;
int l = 1;
int r = n+1;
while (l <= r) {
int m = l + ((r - l) /2);
if (check(m)) {
ans = max(ans, m);
l = m + 1;
} else r = m - 1;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3628kb
input:
5 RWWRRRWWW
output:
2
result:
ok At least n intervals
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 R
output:
0
result:
ok At least n intervals
Test #3:
score: -100
Time Limit Exceeded
input:
1000000 WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW...