ABC C求助
  • 板块学术版
  • 楼主紊莫turtle
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/10/2 06:51
  • 上次更新2023/10/27 09:16:54
查看原帖
ABC C求助
443675
紊莫turtle楼主2022/10/2 06:51

赛时给C不会了,疯狂WA,甚至DE都更好些,一直WA一个点,已经去重了,优先使用重复部分。

#include <bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(int x){write(x);putchar('\n');}
inline void writesp(int x){write(x);putchar(' ');}
int a[300005],n=read(),ans=1;
signed main()
{
	for(int i=1;i<=n;i++) 
		a[i]=read();
	sort(a+1,a+n+1);
	int m=unique(a+1,a+n+1)-a-1,have=n-m;
	// cout<<have<<endl;
	for(int i=1;i<=m||have>1;)
	{
		if(a[i]!=ans) 
		{
			if(have>0)
			{
				if(have>=2)have-=2,ans++;
				else if(i<=m) ans++,m--; 
			}
			else if(i+1<=m) ans++,m-=2;
			else break;
		}
		else ans++,i++;
	}
	writeln(ans-1);
    return 0;
}
2022/10/2 06:51
加载中...