/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'int main()':
/in/foo.cc:10:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     scanf("%lld",&n),ans=n+1,m=n+1>>1;
                                ~^~
# 状态 耗时 内存占用
#1 Accepted 2ms 4.297 MiB
#2 Accepted 3ms 4.258 MiB
#3 Accepted 2ms 4.301 MiB
#4 Accepted 2ms 4.211 MiB
#5 Accepted 14ms 4.934 MiB
#6 Accepted 15ms 6.355 MiB
#7 Accepted 110ms 9.453 MiB
#8 Accepted 100ms 9.426 MiB
#9 Accepted 93ms 9.453 MiB
#10 Accepted 95ms 9.453 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;
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){
                int 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:08:20
评测时间
2020-03-03 08:08:20
评测机
分数
100
总耗时
441ms
峰值内存
9.453 MiB