QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#234674#5543. The Only Modedmmm#WA 1ms5720kbC++171.0kb2023-11-01 20:41:172023-11-01 20:41:19

Judging History

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

  • [2023-11-01 20:41:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5720kb
  • [2023-11-01 20:41:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int MAXN = 1e5 + 6.9;
const int INF = 1e18;
int n;
int a[MAXN];
int pre[MAXN];
int num[MAXN][4];
int check(int len, int val) {
	for (int i = 1; i + len - 1 <= n; i++) {
		int cnt = num[i + len - 1][val] - num[i - 1][val];
		int ok = 1;
		for (int j = 0; j < 4; j++) {
			if (j == val) continue;
			if (cnt <= num[i + len - 1][j] - num[i - 1][j]) ok = 0;
		}
		if (ok) return 1;
	}
	return 0;
}
int bin(int l, int r, int val) {
	while (l < r) {
		int mid = (l + r) / 2 + 1;
		if (check(mid, val)) {
			l = mid;
		}
		else {
			r = mid - 1;
		}
	}
	return l;
}
void solve(int val) {
	int ans = bin(1, n, val);
	if (check(ans, val)) cout << ans << ' ';
	else cout << 0 << ' ';
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 4; j++) num[i][j] = num[i - 1][j];
		num[i][a[i]]++;
	}
	for (int i = 0; i < 4; i++) solve(i);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

input:

7
1 2 2 0 3 0 3

output:

4 1 5 3 

result:

ok single line: '4 1 5 3 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

12
2 0 1 0 2 1 1 0 2 3 3 3

output:

4 9 1 9 

result:

ok single line: '4 9 1 9 '

Test #3:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

2
0 2

output:

1 0 1 0 

result:

ok single line: '1 0 1 0 '

Test #4:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

12
3 0 2 2 1 0 2 1 3 3 2 3

output:

1 5 11 8 

result:

ok single line: '1 5 11 8 '

Test #5:

score: 0
Accepted
time: 1ms
memory: 5720kb

input:

1
1

output:

0 1 0 0 

result:

ok single line: '0 1 0 0 '

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3788kb

input:

4207
3 1 0 3 2 0 3 1 1 1 1 3 0 1 1 0 2 2 3 0 1 1 0 1 0 2 0 1 0 0 3 3 1 0 1 3 3 0 2 0 2 0 1 0 2 3 2 3 0 0 0 0 1 2 1 2 0 2 2 0 3 3 2 2 0 2 2 0 3 0 1 3 1 1 0 2 3 0 1 2 1 2 0 0 1 1 0 3 3 2 0 2 1 3 0 1 0 3 0 0 0 2 2 2 0 1 1 0 3 1 1 3 3 2 2 1 3 3 1 3 2 0 2 3 2 2 1 0 2 3 0 1 0 0 1 1 1 3 3 1 3 3 3 0 0 0 3 2...

output:

1969 1520 4207 1359 

result:

wrong answer 1st lines differ - expected: '2330 1520 4207 1359', found: '1969 1520 4207 1359 '