/ Randle /

记录详情

Time Exceeded


  
# 状态 耗时 内存占用
#1 Accepted 3ms 364.0 KiB
#2 Wrong Answer 3ms 384.0 KiB
#3 Accepted 4ms 384.0 KiB
#4 Accepted 4ms 268.0 KiB
#5 Accepted 27ms 2.867 MiB
#6 Accepted 27ms 1.125 MiB
#7 Time Exceeded ≥1004ms ≥4.875 MiB
#8 Accepted 160ms 5.023 MiB
#9 Accepted 144ms 5.078 MiB
#10 Accepted 162ms 4.898 MiB

代码

#include<bits/stdc++.h>
#define maxn 700000
using namespace std;
int n,k;
int ans=100000;
struct node
{
	int data,v;
}a[maxn];
inline const void read(int &a)
{
	a=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	 } 
}
bool com(node aa,node bb)
{
	return aa.data<bb.data;
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int x1,x2;
	read(n);
	if(n%2==0)
	k=n/2;
	else k=n/2+1;
	for(int i=0;i<n;i++)
	{
		read(x1);read(x2);
	    if(x1==x2)
	    	a[i*2].v=3,a[i*2+1].v=4;
	    else a[i*2].v=1,a[i*2+1].v=2;
	    a[i*2].data=x1;
	    a[i*2+1].data=x2;
	}
	sort(a,a+2*n,com);
	int temp=1,step=0;
	if(a[0].v==1)
	step=1;
	for(int i=1;i<=2*n;i++)
	{
		if(a[i].data==a[i-1].data)
		{
			if(a[i].v!=4)
			temp++;
			if(a[i].v==1||a[i].v==3)
			step++;
		}
		else {
			if(temp>=k)
			{
				if(k-step<0)
				ans=0;
				else ans=min(ans,k-step);
			}
			if(a[i].v!=4)
			temp=1;
			else temp=0;
			if(a[i].v==1||a[i].v==3)
			step=1;
			else step=0;
		}
	}
	if(ans!=100000)
	cout<<ans<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}

信息

递交者
类型
递交
题目
纸牌
题目数据
下载
语言
C++
递交时间
2017-11-07 16:45:07
评测时间
2017-11-07 16:45:07
评测机
分数
80
总耗时
≥1541ms
峰值内存
≥5.078 MiB