比赛 “Asm.Def战记之夏威夷”杯 评测结果 TWWTTWTTWW
题目名称 Asm.Def的验证码 最终得分 0
用户昵称 Collor 运行时间 5.008 s
代码语言 C++ 内存使用 1.84 MiB
提交时间 2015-11-06 11:56:51
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<ctime>
using namespace std;
const int  maxn=100001;
struct node
{
	int num;
	int add;
}a[maxn],b[maxn];
inline int read()
{
	int x=0;char ch;
	ch=getchar();
	while (ch<'0'||ch>'9'){ch=getchar();}
	while (ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x;
}
int n,k1=0,k2=0;
bool f1=0;
long long ans=0;
void init()
{
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	n=read();
	int temp,x,sum=0;
	a[k1].add=b[k2].add=0;
	
	x=read();
	temp=x;
	sum=1;
	if (x==1){
		a[1].num=sum;
		a[1].add=1;
		f1=1;
	}
	else {
		b[1].num=sum;
		b[1].add=1;
	}
	for (int i=2;i<=n;i++){
		x=read();
		while (temp==x)
		{
			sum++;
			x=read();
			i++;
		}
		if (temp==1){a[++k1].num=sum;
			a[k1].add=a[k1-1].add+sum;
		}
		else {b[++k2].num=sum;
			b[k2].add=b[k2-1].add+sum;
		}
		sum=1;
		temp=x;
	}
}
void work1()
{
	int m=max(k1,k2);
	for (int i=2;a[i].num;i++) {
		ans+=(a[i].num*a[i-1].add*1LL);
		ans+=(b[i].num*b[i-1].add*1LL);
	}
}
void work2()
{
	int m=max(k1,k2);
	for (int i=2;b[i].num;i++) {
		ans+=(a[i].num*a[i-1].add*1LL);
		ans+=(b[i].num*b[i-1].add*1LL);
	}
}
int main()
{
	freopen("asm_code.in","r",stdin);
	freopen("asm_code.out","w",stdout);
	init();
	if (f1)work1();
	else work2();
	cout<<ans<<'\n';
	return 0;
}