/ Randle /

记录详情

Time Exceeded


  
# 状态 耗时 内存占用
#1 Time Exceeded ≥1008ms ≥256.0 KiB
#2 Time Exceeded ≥1002ms ≥360.0 KiB
#3 Time Exceeded ≥1007ms ≥384.0 KiB
#4 Time Exceeded ≥1009ms ≥384.0 KiB
#5 Time Exceeded ≥1005ms ≥212.0 KiB
#6 Time Exceeded ≥1006ms ≥376.0 KiB
#7 Time Exceeded ≥1007ms ≥360.0 KiB
#8 Time Exceeded ≥1007ms ≥372.0 KiB
#9 Time Exceeded ≥1006ms ≥336.0 KiB
#10 Time Exceeded ≥1007ms ≥384.0 KiB

代码

#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:44:53
评测时间
2017-11-07 16:44:54
评测机
分数
0
总耗时
≥10069ms
峰值内存
≥384.0 KiB