/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 2ms 4.211 MiB
#2 Accepted 2ms 4.207 MiB
#3 Accepted 2ms 4.215 MiB
#4 Accepted 2ms 4.305 MiB
#5 Accepted 14ms 6.602 MiB
#6 Accepted 15ms 6.867 MiB
#7 Accepted 104ms 9.453 MiB
#8 Accepted 94ms 9.359 MiB
#9 Accepted 93ms 9.449 MiB
#10 Accepted 95ms 9.457 MiB

代码

//card
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e5+5;
int n,a[N],b[N],x[N<<1],cnt,ans,sum,m,t;
signed main(){
    //freopen("card.in","r",stdin);
    //freopen("card.out","w",stdout);
    scanf("%lld",&n),ans=n+1,m=(n+1)>>1;
    for(int i=1;i<=n;i++){
    	scanf("%lld%lld",&a[i],&b[i]);
    	x[++cnt]=a[i];
    	if(a[i]!=b[i]) x[++cnt]=b[i];
    }
    sort(x+1,x+cnt+1);
    for(int i=1;i<=cnt;i++){
        if(x[i]==x[i-1]){
            ++sum;
            if(sum==m){
                t=0;
                for(int j=1;j<=n;j++)
					if(a[j]==x[i]) t++;
                t=min(t,m),ans=min(ans,m-t);
            }        
        }
        else sum=1;
    }
    if(ans>n) printf("Impossible\n");
    else printf("%lld\n",ans);
    return 0;
}

信息

递交者
类型
递交
题目
纸牌
题目数据
下载
语言
C++
递交时间
2020-03-03 08:09:05
评测时间
2020-03-03 08:09:05
评测机
分数
100
总耗时
428ms
峰值内存
9.457 MiB