QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#168697#6540. Beautiful SequencePhantomThreshold#WA 1ms3448kbC++201.4kb2023-09-08 19:44:462023-09-08 19:44:47

Judging History

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

  • [2023-09-08 19:44:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3448kb
  • [2023-09-08 19:44:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn=300000;

int T;
int n;
int a[maxn+50];
int ans=0;

bool check(int k){
//	cerr << "----------------" << endl;
//	cerr << "check : " << k << endl;
	int cnt=0;
	for (int l=k+1,r=k+1;l<=n;l=r){
		for (;r<=n && a[l]==a[r];) r++;
		cnt++;
	}
//	cerr << "cnt : " << cnt << endl;
	if (cnt>k+1) return false;
	vector<int> tmp;
	tmp.push_back(0);
	int pos=1;
	for (int l=k+1,r=k+1;l<=n;l=r){
		for (;r<=n && a[l]==a[r];) r++;
		if (a[l]<tmp.back()) return false;
		if (pos!=k+1 && a[l]<a[pos]) return false;
	//	cerr << "l,r,pos : " << l << " " << r << " " << pos << endl;
		for (int t=l;t<r;t++) tmp.push_back(a[t]);
		if (pos!=k+1) tmp.push_back(a[pos]);
		pos++;
	}
	for (;pos<=k;pos++) tmp.push_back(a[pos]);
	tmp.push_back(0);
	//assert(tmp.size()==n+2);
	int nowans=0;
	for (int i=1;i<=n;i++) if (tmp[i]>=tmp[i-1] && tmp[i]>=tmp[i+1]) nowans++;
	
//	for (auto e:tmp) cerr << e << " ";
//	cerr << endl;
//	cerr << "nowans : " << nowans << endl;
	
	ans=max(ans,nowans);
	return true;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin >> T;
	for (;T--;){
		cin >> n;
		for (int i=1;i<=n;i++) cin >> a[i];
		sort(a+1,a+n+1);
		
		int l=1,r=n;
		for (;l<r;){
			int mid=(l+r)>>1;
			if (check(mid)) r=mid;
			else l=mid+1;	
		}
		check(l);
		cout << ans << "\n";
		ans=0;
	}
	return 0;	
}

詳細信息

Test #1:

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

input:

2
6
1 1 2 3 3 4
5
1 2 2 3 3

output:

4
4

result:

ok 2 number(s): "4 4"

Test #2:

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

input:

2
5
1 2 2 3 3
20
1 1 1 1 1 1 4 5 8 8 8 8 9 9 9 9 10 10 10 10

output:

4
15

result:

wrong answer 2nd numbers differ - expected: '17', found: '15'