53分TLE求调。
  • 板块学术版
  • 楼主poor_OIer
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/10 22:01
  • 上次更新2024/8/11 00:12:53
查看原帖
53分TLE求调。
704634
poor_OIer楼主2024/8/10 22:01

P10840 【MX-J2-T1】Turtle and Sequences

TLE Substack#3 #14

#include<bits/stdc++.h>
using namespace std;
int n,ans;
struct node{
	int from;
	int next;
	int weight;
}a[100005];
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i].weight=read(),a[i].from=i-1,a[i].next=i+1;
	while(1)
	{
		bool flag=0;
		for(int i=1;i<n;i=a[i].next)
		{
			if(a[a[i].next].weight!=a[i].weight||a[a[i].next].weight==-1||a[i].weight==-1)
			{
				flag=1;
				n--;
				ans++;
				a[i].next=a[a[i].next].next;
				a[a[i].next].from=i;
				a[i].weight=-1;
			}
		}
		if(!flag)
			break;
	}
	cout<<ans;
	return 0;
}
2024/8/10 22:01
加载中...