# 题意

#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
#define out(x) cout<<#x<<": "<<x<<endl
const double eps(1e-8);
const int maxn=2100;
const long long maxint=-1u>>1;
const long long maxlong=maxint*maxint;
typedef long long lint;
#define maxnode 41000
#define sigma_size 26
int n, sum[maxn];
char s[maxn];
int f[maxn];
int num[300], g[maxn];

bool isprime(int x)
{
for (int i=2; i*i<=x; i++)
if (x%i==0) return false;
return true;
}

void init()
{
scanf("%s",s);
n=strlen(s);
for (int i=0; i<n; i++)
num[s[i]]++;
}
struct node
{
int x,time;
} a[maxn], b[maxn];

bool cmp(node a, node b)
{
return a.time>b.time;
}

void work()
{
memset(f,0,sizeof(f));
for (int i=2; i<=n; i++)
if (isprime(i)) {
for (int k=i; k<=n; k+=i)
{
if (f[k]) {
int old=f[k];
for (int x=1; x<=n; x++)
if (f[x]==old) f[x]=i;
}
f[k]=i;
}

//  cout<<"--------"<<i<<endl;
// for (int i=0; i<=n; i++)
// cout<<i<<" "<<f[i]<<endl;
}

for (int i=1; i<=n; i++)
sum[f[i]]++;
for (int i=0; i<=n; i++)
a[i].x=i,a[i].time=sum[i];
sort(a+1,a+n+1,cmp);

//for (int i=0; i<=n; i++)
//cout<<i<<" "<<f[i]<<endl;
//for (int i=0; i<=n; i++)
//cout<<a[i].x<<" "<<a[i].time<<endl;

for (int i='a'; i<='z'; i++)
b[i-'a'+1].x=i,b[i-'a'+1].time=num[i];
sort(b+1,b+1+26,cmp);

//for (int i=1; i<=26; i++)
//cout<<(char)b[i].x<<" "<<b[i].time<<endl;

bool flag=true;
for (int i=1; i<=n; i++)
{
if (a[i].time==0) continue;
int tmp=0;
for (int j=1; j<=26; j++)
if (b[j].time>=a[i].time && ((tmp==0) || (b[j].time>b[tmp].time)))
tmp=j;
//cout<<i<<": "<<tmp<<endl;
//out(a[i].time);
//out(b[tmp].time);
if (tmp==0) {
flag=false;
break;
}
g[a[i].x]=b[tmp].x;
b[tmp].time-=a[i].time;
}
//for (int i=1; i<=26; i++)
//cout<<(char)b[i].x<<" "<<b[i].time<<endl;

if (!flag) {
cout<<"NO"<<endl;
return;
} else cout<<"YES"<<endl;

char wjj[maxn];
for (int i=0; i<n; i++)
{
if (f[i+1]!=0) {
wjj[i]=g[f[i+1]];
//    out(i);
//  out(f[i]);
//  out(g[f[i]]);
} else
{
for (int j=1; j<=26; j++)
if (b[j].time>0) {
wjj[i]=b[j].x;
b[j].time--;
}
}
}

wjj[n]='\0';
cout<<wjj<<endl;

}

int main()
{

init();
work();
return 0;
}


# 参考

08-19 935

01-27 78

01-30 25

06-17 464

03-24 6408

12-15 939

08-01 828

06-26 428

05-07 588

09-24 651

#### codeforce 719b 贪心

©️2020 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。