90分,第二个点TLE
  • 板块P1246 编码
  • 楼主jyyzzzy
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/11/27 12:17
  • 上次更新2023/11/3 23:29:18
查看原帖
90分,第二个点TLE
172057
jyyzzzy楼主2021/11/27 12:17
#include<bits/stdc++.h>
using namespace std;
char s[10];
int a[10],r[10];
int sum,ans,ls,lr,t;
bool pd()
{
	for(int i=0; i<6; i++)
		if(a[i]!=r[i])
			return false;
	return true;
}
int main()
{
	//freopen("slyar.in","r",stdin);
	//freopen("slyar.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>s;
	ls=strlen(s);
	if(ls>6)
	{
		cout<<0;
		return 0;
	}
	for(int i=0; i<ls; i++)
		a[i]=s[ls-i-1]-'a'+1;
	for(int i=0; i<ls-1; i++)
		if(a[i]<a[i+1]||!(a[i]>=1&&a[i]<=26&&a[i+1]>=1&&a[i+1]<=26))
		{
			cout<<0;
			return 0;
		}
	int x=0;
	while(1)
	{
		t=0;
		r[0]++;
		ans++;
		while(r[t]>26-t)
		{
			if(r[lr]>26-lr)
			{
				for(int i=0; i<=lr+1; i++)
					r[i]=lr-i+2;
				lr++;
				break;
			}
			r[t+1]++;
			for(int i=0; i<=t; i++)
				r[i]=r[t+1]+t-i+1;
			t++;
		}
		if(pd())
		{
			cout<<ans;
			return 0;
		}
		//cout<<ans<<' ';
		//for(int i=0;i<=lr;i++)
		//cout<<r[i]<<' ';
		//cout<<"\n";
	}
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}
2021/11/27 12:17
加载中...