QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84033#5647. Another Wine Tasting EventBervigWA 54ms91060kbC++141.6kb2023-03-05 03:54:032023-03-05 03:54:07

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-05 03:54:07]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:91060kb
  • [2023-03-05 03:54:03]
  • 提交

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;
}

详细

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