QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425709#6540. Beautiful SequencecqbzlyWA 1ms5764kbC++201.2kb2024-05-30 16:01:412024-05-30 16:01:45

Judging History

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

  • [2024-05-30 16:01:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5764kb
  • [2024-05-30 16:01:41]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long 
#define fi first
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
using namespace std;
const int N=3e5+5;
//不会贪心 
int T,n,a[N],lsh[N],cnt,c[N],fk[N],it,flg;
int get(int x){
	return lower_bound(lsh+1,lsh+1+cnt,x)-lsh;
}
void cng(int x){
	fk[x]++;
	it=min(it,x);
}
int main(){
//    freopen("data.in","r",stdin);
//    freopen("puzzle.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>T;
    while(T--){
    	cin>>n,cnt=0;
    	for(int i=1;i<=n;i++)cin>>a[i],lsh[++cnt]=a[i];
    	sort(lsh+1,lsh+1+cnt),cnt=unique(lsh+1,lsh+1+cnt)-lsh-1;
    	for(int i=1;i<=cnt;i++)c[i]=0;
    	for(int i=1;i<=n;i++)c[get(a[i])]++;
    	for(int i=1;i<=n;i++)fk[i]=0;
    	flg=0,it=n+1;int res=n-cnt+1;
		for(int i=1;i<cnt;i++){
    		if(flg){
    			//需要c[i]+1次才能搞定 
    			cng(c[i]),flg=0;
			}
			else if(c[i]<=it){
				if(c[i]==1)flg=1,res++;
				else cng(c[i]-1);
			}
			else{
				fk[it]--,cng(c[i]-1);
				if(it==1){
					flg=1,res++;
					while(it<=n&&!fk[it])it++;
				}
				else{
					cng(it-1);
				}
			}
		}
		cout<<res-flg<<"\n";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 1ms
memory: 5656kb

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
17

result:

ok 2 number(s): "4 17"

Test #3:

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

input:

300
14
1 1 1 2 2 2 3 3 3 4 5 5 6 6
14
1 1 1 2 2 3 3 4 4 5 5 6 7 7
14
1 1 2 2 3 4 4 4 5 5 5 6 6 6
14
1 1 2 2 3 3 3 4 5 5 5 6 6 6
14
1 1 1 1 1 1 2 2 2 2 2 3 3 3
14
1 1 1 1 1 1 1 1 1 1 1 1 1 1
14
1 2 2 3 4 5 5 6 6 6 7 8 8 8
14
1 2 2 2 2 2 3 4 5 6 7 8 9 10
14
1 2 2 3 4 4 4 5 6 6 6 6 6 7
14
1 1 2 2 2 3 3...

output:

10
10
11
11
12
14
10
9
11
11
9
10
10
9
11
11
11
9
9
12
10
9
10
10
11
10
11
11
11
11
10
8
10
10
10
10
11
13
10
12
11
11
9
10
10
11
11
10
10
8
11
10
11
10
10
10
10
10
11
11
12
9
10
10
10
10
9
10
11
11
10
10
10
10
11
10
10
10
10
9
9
10
8
11
9
11
10
11
11
12
9
9
10
9
12
11
10
11
10
10
11
10
10
9
10
9
10...

result:

wrong answer 2nd numbers differ - expected: '9', found: '10'