QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153116#5647. Another Wine Tasting EventabzcodesTL 2ms3468kbC++171.4kb2023-08-29 13:07:582023-08-29 13:07:59

Judging History

你现在查看的是最新测评结果

  • [2023-08-29 13:07:59]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3468kb
  • [2023-08-29 13:07:58]
  • 提交

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

void solve() {
	int n; cin >> n;
	string S; cin >> S;
	vector<int> whites(2*n - 1, 0);
	
	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;
		//cout << w << ": \n";
		for (int i = 0; i < 2*n - 1; i++) {
			int v = whites[i];
			auto llidx = ub(all(whites), v) - whites.begin();
			auto ll = llidx - i;
			if (S[i] != 'W') {
				ll++;
			} else ll = 1;
			int need = v + w - (S[i] == 'W');
			auto rr = ub(all(whites), need);
			auto rrl = lb(all(whites), need);
			long long diff = rr - rrl;
			if (diff == 0) continue;
			
			diff = max(diff, 1LL);
			
			count += ll*1LL*diff;
			//cout << "\t" << i << ": " << ll << ", " << diff << " end=" << (rr - whites.begin()) << '\n';
			if (count >= n) return true; 
			i = llidx - (S[i] == 'W');
		}
		return false;
	};
	int ans = 0;
	int l = 1;
	int r = 2*n;
	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);
  solve();
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3384kb

input:

5
RWWRRRWWW

output:

2

result:

ok At least n intervals

Test #2:

score: 0
Accepted
time: 2ms
memory: 3468kb

input:

1
R

output:

0

result:

ok At least n intervals

Test #3:

score: -100
Time Limit Exceeded

input:

1000000
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW...

output:


result: