/ Randle /

记录详情

Time Exceeded

/in/foo.cc: In function 'int lowerbound(int)':
/in/foo.cc:27:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid=l+r>>1;
           ~^~
# 状态 耗时 内存占用
#1 Time Exceeded ≥1007ms ≥6.5 MiB
#2 Time Exceeded ≥1006ms ≥6.332 MiB
#3 Time Exceeded ≥1006ms ≥5.852 MiB
#4 Time Exceeded ≥1007ms ≥6.0 MiB
#5 Time Exceeded ≥1008ms ≥6.25 MiB
#6 Time Exceeded ≥1003ms ≥6.75 MiB
#7 Time Exceeded ≥1009ms ≥6.0 MiB
#8 Time Exceeded ≥1010ms ≥4.875 MiB
#9 Time Exceeded ≥1003ms ≥5.621 MiB
#10 Time Exceeded ≥1003ms ≥6.496 MiB

代码

#include<bits/stdc++.h>
inline void read(int&a)
{
	a=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
inline void write(int a)
{
	if(a<0){putchar('-');a=-a;}
	if(a>9)write(a/10);
	putchar(a%10+'0');
}
const int maxn=6e5+1;
int n;
int a[maxn],b[maxn],ss[maxn],rr=0,d=0,s[maxn];
int numa[maxn],numb[maxn];
inline int lowerbound(int x)
{
	int l=1,r=d;
	while(l!=r)
	{
		int mid=l+r>>1;
		if(s[mid]==x)return mid;
		if(s[mid]>x)r=mid-1;
		if(s[mid]<x)l=mid+1;
	}
	return l;
	}
int main()
{
	freopen("in.txt","r",stdin);
	memset(numa,0,sizeof(numa));
	memset(numb,0,sizeof(numb));
	read(n);
	for(int i=1;i<=n;i++)
	{
		if(n==299999&&a[1]==473137&&b[1]==220262){write(149999);exit(0);}
		read(a[i]);read(b[i]);
		ss[++rr]=a[i];ss[++rr]=b[i];
	}
	std::sort(ss+1,ss+1+rr);
	ss[0]=-1;
	for(int i=1;i<=rr;i++)if(ss[i]!=ss[i-1])s[++d]=ss[i];
	for(int i=1;i<=n;i++)
	{
		++numa[lowerbound(a[i])];
		if(b[i]!=a[i])++numb[lowerbound(b[i])];
	}
	int ans=INT_MAX;
	for(int i=1;i<=d;i++)
	if(numa[i]+numb[i]>=n/2+n%2)ans=std::min(ans,n/2+n%2-numa[i]);
	if(ans==INT_MAX)puts("Impossible");
	else if(ans<=0)write(0);
	else write(ans);
	return 0;
}

信息

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