/ Randle /

记录详情

Time Exceeded

/in/foo.cc:1:0: warning: ignoring #pragma G  [-Wunknown-pragmas]
 #pragma G++ optimize ("O2")
 
# 状态 耗时 内存占用
#1 Accepted 1ms 196.0 KiB
#2 Wrong Answer 1ms 204.0 KiB
#3 Accepted 1ms 332.0 KiB
#4 Accepted 1ms 212.0 KiB
#5 Accepted 12ms 316.0 KiB
#6 Accepted 54ms 3.855 MiB
#7 Time Exceeded ≥1004ms ≥30.125 MiB
#8 Accepted 199ms 1.254 MiB
#9 Wrong Answer 543ms 23.0 MiB
#10 Accepted 187ms 3.688 MiB

代码

#pragma G++ optimize ("O2")
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
map<int,int>f1;
map<int,int>f2;
int n;
int a[599999];
int cnt=0;
int main()
{
//    freopen("card.in","r",stdin);
//    freopen("card.out","w",stdout);
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&x,&y);
		if(x==y)
		{
	      if(f1[x]==0)
	        a[++cnt]=x;
		  f1[x]++;
		  f1[y]++;
		  f1[x]--;
		}
		else
		{
			if(f1[x]==0)
	          a[++cnt]=x;
	        if(f1[y]==0)
	          a[++cnt]=y;
			f1[x]++;
		    f1[y]++;
		}
		f2[x]++;
	}
	int m=(n+1)/2,b=0;
	for(int i=1;i<=cnt;i++)
	{
//		cout<<a[i]<<' '<<f1[a[i]]<<' '<<f2[a[i]]<<endl;
		if(f1[a[i]]>=m)
		  b=1;
		break; 
	}
	if(b==0)
	{
	  printf("Impossible");
      return 0;
	}
	int minn=1e9;
	for(int i=1;i<=cnt;i++)
	{
		int ans=0;
		if(f1[a[i]]>=m)
		  ans=m-f2[a[i]];
		else
		  ans=1e9;
		minn=min(minn,max(ans,0));;
	}
	printf("%d",minn);
	return 0;
}

信息

递交者
类型
递交
题目
纸牌
题目数据
下载
语言
C++
递交时间
2019-12-13 18:15:21
评测时间
2019-12-13 18:15:21
评测机
分数
70
总耗时
≥2009ms
峰值内存
≥30.125 MiB