QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#558757#8829. AibohphobialntanoTL 0ms3540kbC++14943b2024-09-11 18:25:082024-09-11 18:25:08

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 18:25:08]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3540kb
  • [2024-09-11 18:25:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

void solve(){
	string s;
	cin>>s;

	int n=s.size();
	map<int,int> mp;
	for(int i=0;i<n;i++) mp[s[i]-'a']++;

	int p=0,mn=1e9;
	for(auto [k,v]:mp){
		if(v<mn){
			mn=v;
			p=k;
		}
	}


	string ans="";
	int cnt=0;
	for(int i=1;i<=n;i++){
		if((i&1)&&mp[p]){
			ans+=p+'a';
			mp[p]--;
		}
		else{
			while(!mp[cnt]||cnt==p){
				cnt++;
				if(cnt>26) cnt=0;
			}
			mp[cnt]--;
			ans+='a'+cnt;
			cnt++;
			if(cnt>26) cnt=0;
		}
	}

	if(mn==1){
		cout<<"YES\n";
		cout<<ans<<'\n';
		return;
	}

	string s1="",s2;
	for(int i=0;i<n;i++){
		s1+=ans[i];
		s2=s1;
		reverse(s2.begin(),s2.end());
		if(s1==s2){
			cout<<"NO\n";
			return;
		}
	}

	cout<<"YES\n";
	cout<<ans<<'\n';
}

int main(){
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);

	int t=1;
	cin>>t;
	while(t--) solve();

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

input:

5
a
sos
abba
icpc
tenet

output:

YES
a
YES
oss
NO
YES
icpc
YES
netet

result:

ok Correct (5 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

18
qnx
oooo
tvttj
zzzzz
pvlne
iijt
hjhjj
loo
hh
uq
mgvgv
ewwe
iii
kykk
o
mmumm
aetvv
xntl

output:


result: