/ Randle /

记录详情

Memory Exceeded


  
# 状态 耗时 内存占用
#1 Accepted 3ms 6.191 MiB
#2 Accepted 3ms 6.199 MiB
#3 Wrong Answer 3ms 6.309 MiB
#4 Wrong Answer 3ms 6.195 MiB
#5 Accepted 13ms 6.508 MiB
#6 Time Exceeded ≥1000ms ≥9.398 MiB
#7 Time Exceeded ≥1001ms ≥10.844 MiB
#8 Wrong Answer 998ms 9.508 MiB
#9 Memory Exceeded ≥197ms ≥256.0 MiB
#10 Wrong Answer 442ms 235.012 MiB

代码

#include<bits/stdc++.h>
using namespace std;
int n,l,cnt,need,maxx,x[300010],y[300010];
int b[700010],c[700010],d[30],e[30];
bool v[1000000010];
int main()
{
//	freopen("card.in","r",stdin);
//	freopen("card.out","w",stdout);
	scanf("%d",&n);
	need=(n+1)/2;
	for (int i=1;i<=n;i++) {
		scanf("%d%d",&x[i],&y[i]);
		if (!v[x[i]]) {
			v[x[i]]=1;
			b[++cnt]=x[i];
			c[cnt]=1;
			if (1>=maxx) {
			   	if (1==maxx) l++;
				else l=1;
				d[l]=x[i];
			 	maxx=1;
			}
		}
		else {
			for (int j=1;j<=cnt;j++)
			    if (b[j]==x[i]) {
			    	c[j]++;
			    	if (c[j]>=maxx) {
			    		if (c[j]==maxx) l++;
						else l=1;
						d[l]=x[i];
			    		maxx=c[j];
					}
			    	break;
				}
		}
		if (!v[y[i]]&&x[i]!=y[i]) {
			v[y[i]]=1;
			b[++cnt]=y[i];
			c[cnt]=1;
			if (1>=maxx) {
			   	if (1==maxx) l++;
				else l=1;
				d[l]=y[i];
			 	maxx=1;
			}
		}
		else {
			for (int j=1;j<=cnt;j++)
			    if (b[j]==y[i]) {
			    	c[j]++;
			    	if (c[j]>=maxx) {
			    		if (c[j]==maxx) l++;
						else l=1;
						d[l]=y[i];
			    		maxx=c[j];
					}
			    	break;
				}
		}
	}
	if (maxx<need) {
		puts("Impossible");
		return 0;
	}
	maxx=0;
	for (int i=1;i<=n;i++)
	    for (int j=1;j<=l;j++)
	        if (x[i]==d[j]) {
	        	e[j]++;
	        	maxx=max(maxx,e[j]);
			}
	printf("%d",max(0,need-maxx));
}

信息

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