/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 1ms 192.0 KiB
#2 Accepted 1ms 212.0 KiB
#3 Accepted 1ms 332.0 KiB
#4 Accepted 1ms 204.0 KiB
#5 Accepted 11ms 296.0 KiB
#6 Accepted 43ms 3.273 MiB
#7 Accepted 778ms 22.406 MiB
#8 Accepted 165ms 924.0 KiB
#9 Accepted 568ms 18.539 MiB
#10 Accepted 134ms 2.941 MiB

代码

#include <utility>
#include <cstdio>
#include <cmath>
#include <map>

typedef std::pair<long long,long long> count;

std::map<long long,count> c;

int main()
{
	// freopen("card.in","r",stdin);
	// freopen("card.out","w",stdout);
	int n;
	scanf("%d",&n);
	bool check=false;
	long long need=(n+1)>>1;
	for(int i=0;i<n;i++)
	{
		long long a,b;
		scanf("%lld%lld",&a,&b);
		c[a].first++;
		if(a!=b)
		{
			c[b].first++;
			c[b].second++;
		}
		if(c[a].first>=need) check|=true;
		if(c[b].first>=need) check|=true;
	}
	if(!check) puts("Impossible");
	else
	{
		long long min=n>>1;
		for(std::map<long long,count>::iterator i=c.begin();i!=c.end();i++)
			if((i->second).first>=need)
				min=std::min(min,std::max(0LL,need-(i->second).first+(i->second).second));	
		printf("%lld\n",min);
	}
	return 0;
}

信息

递交者
类型
递交
题目
纸牌
题目数据
下载
语言
C++
递交时间
2019-12-13 17:37:56
评测时间
2019-12-13 17:37:56
评测机
分数
100
总耗时
1709ms
峰值内存
22.406 MiB