求助
查看原帖
求助
1274550
chenyuheng01楼主2024/10/2 22:01

TLE on 点 #9-#23

// Problem: P11138 [APC001] C - Not APC
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P11138?contestId=126344
// Memory Limit: 500 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		string str;
		cin>>str;
		bool flag=true;
		int n=str.size();
		queue<tuple<int,int,int>> q;
		while(flag)
		{
			
			flag=false;
			for(int i=0;i<n;i++)
			{
				if(str[i]=='A')
				{
					for(int j=i+1;j<n;j++)
					{
						if(str[j]=='P')
						{
							for(int k=j+1;k<n;k++)
							{
								if(str[k]=='C')
								{
									q.push(make_tuple(i+1,j+1,k+1));
									str[i]='#';
									str[j]='#';
									str[k]='#';
									flag=true;
									break;
								}
							}
						}
						if(flag) break;
					}
				}if(flag) break;
			}
		}
		bool t=true;
		for(int i=0;i<n;i++)
		{
			if(str[i]!='#') {cout<<str[i];t=false;}
		} 
		if(t) cout<<"Perfect";cout<<endl;
		cout<<q.size()<<endl;
		while(!q.empty())
		{
			cout<<get<0>(q.front())<<' '<<get<1>(q.front())<<' '<<get<2>(q.front())<<endl;
			q.pop();
		}
	}
}

必关

2024/10/2 22:01
加载中...