dalao 们能不能帮我看看TLE还有救吗?QWQ
查看原帖
dalao 们能不能帮我看看TLE还有救吗?QWQ
931492
xiaohuanxiong楼主2025/1/20 19:19
#include<bits/stdc++.h>
using namespace std; 
long long t,ac,pc,cc,cnt=0;
char s[300001]={};
long long a[300001]={},p[300001]={},c[300001]={};
int main()
{
	cin>>t;
	while (t--)
	{
		ac=0;pc=0;cc=0;cnt=0;
		cin>>s;
		for (int i=0;i<strlen(s);i++)
		{
			 if (s[i]=='A'){
				a[++ac]=i+1;
			}
			if (s[i]=='P'&&ac>pc){
				p[++pc]=i+1;
			} 
			if (s[i]=='C'&&pc>cc){
				cnt++;
				s[i]=' ';
				s[a[cnt]-1]=' ';
				s[p[cnt]-1]=' ';
				c[++cc]=i+1;
			}
		}
		if (3*cnt!=strlen(s)){
			for (int i=0;i<strlen(s);i++)
			{
				if (s[i]!=' ')
					cout<<s[i];
			}
		}
		else{
			cout<<"Perfect";
		}
		cout<<endl<<cnt<<endl;
		for (int i=1;i<=cnt;i++)
		{
			cout<<a[i]<<" "<<p[i]<<" "<<c[i]<<endl;
		}
	}
    return 0; 
}
2025/1/20 19:19
加载中...