#ABC264D. 相邻字符交换

相邻字符交换

相邻字符交换

题目描述

给定一个字符串 SS,它是 atcoder 的一个排列。

你可以对 SS 执行以下操作 00 次或多次:

  • 选择 SS 中两个相邻的字符并交换它们。

求使 SS 变为 atcoder 所需的最少操作次数。

输入格式

SS

输出格式

输出答案,答案为一个整数。

样例

catredo
8

可以通过如下 88 次操作使 SS 变为 atcoder:

catredo →\rightarrow [ac]tredo →\rightarrow actre[od] →\rightarrow actr[oe]d →\rightarrow actro[de] →\rightarrow act[or]de →\rightarrow acto[dr]e →\rightarrow a[tc]odre →\rightarrow atcod[er]

这是可实现的最少操作次数。

atcoder
0

此时字符串 SS 已经是 atcoder。

redocta
21

数据范围

  • SS 是 atcoder 的一个排列。
难度 普及+/提高-
通过率 —
尝试 0
通过 0
ID
2475
类型
传统题
Time Limit
2000ms
Memory Limit
1024MiB
上传者
标签