PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000075. Giảm giá trị số nguyên (Minimize The Integer)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Giảm giá trị số nguyên (Minimize The Integer)
Minimize The Integer
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a string of digits, swap adjacent digits only if their parities differ. Find the lexicographically smallest reachable string, preserving length (leading zeros may appear).
Input
A single digit string , no case count .
Output
Print the lexicographically smallest reachable digit string.
Subtasks
- Subtask 1 (20 points): Exactly one dataset; ; all characters are digits, leading zeros are allowed.
- Subtask 2 (30 points): Exactly one dataset; ; all characters are digits, leading zeros are allowed.
- Subtask 3 (50 points): Exactly one dataset; ; all characters are digits, leading zeros are allowed.
Example
Input
13542
Output
13425
Explanation
Preserve the relative order of even digits and of odd digits and merge their two sequences greedily.