PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000146. Hoán vị chuỗi tại chỉ số nguyên tố (Prime Permutation)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hoán vị chuỗi tại chỉ số nguyên tố (Prime Permutation)
Prime Permutation
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Permute the lowercase letters of so that for every prime and every , positions and contain equal characters. Print YES and a permutation, otherwise NO.
Input
One line containing string .
Output
Print YES and the rearranged string, or NO.
Subtask
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Example
Input
xxxyxxx
Output
YES
xxxxxxy
Explanation
The prime positions 2 and 3 and their multiples 4 and 6 all have the letter x. Reordering preserves the input character counts.