A14299 | String Distance
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Suppose you are given two strings $a$ and $b$ . You can apply the following operation any number of times: choose any contiguous substring of $a$ or $b$ , and sort the characters in it in non-descending order. Let $f(a, b)$ the minimum number of operations you have to apply in order to make them equal (or $f(a, b) = 1337$ if it is impossible to make $a$ and $b$ equal using these operations).
For example:
- $f(\text{ab}, \text{ab}) = 0$ ;
- $f(\text{ba}, \text{ab}) = 1$ (in one operation, we can sort the whole first string);
- $f(\text{ebcda}, \text{ecdba}) = 1$ (in one operation, we can sort the substring of the second string starting from the $2$ -nd character and ending with the $4$ -th character);
- $f(\text{a}, \text{b}) = 1337$ .
You are given $n$ strings $s_1, s_2, \dots, s_k$ having equal length. Calculate $\sum \limits_{i = 1}^{n} \sum\limits_{j = i + 1}^{n} f(s_i, s_j)$ .
For example:
- $f(\text{ab}, \text{ab}) = 0$ ;
- $f(\text{ba}, \text{ab}) = 1$ (in one operation, we can sort the whole first string);
- $f(\text{ebcda}, \text{ecdba}) = 1$ (in one operation, we can sort the substring of the second string starting from the $2$ -nd character and ending with the $4$ -th character);
- $f(\text{a}, \text{b}) = 1337$ .
You are given $n$ strings $s_1, s_2, \dots, s_k$ having equal length. Calculate $\sum \limits_{i = 1}^{n} \sum\limits_{j = i + 1}^{n} f(s_i, s_j)$ .
输入格式
The first line contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of strings.
Then $n$ lines follow, each line contains one of the strings $s_i$ , consisting of lowercase Latin letters. $|s_1| = |s_2| = \ldots = |s_n|$ , and $n \cdot |s_1| \le 2 \cdot 10^5$ . All these strings are pairwise distinct.
Then $n$ lines follow, each line contains one of the strings $s_i$ , consisting of lowercase Latin letters. $|s_1| = |s_2| = \ldots = |s_n|$ , and $n \cdot |s_1| \le 2 \cdot 10^5$ . All these strings are pairwise distinct.
输出格式
Print one integer: $\sum \limits_{i = 1}^{n} \sum\limits_{j = i + 1}^{n} f(s_i, s_j)$ .
输入输出样例
输入 #1
4 zzz bac abc acb
输出 #1
4015
输入 #2
2 a b
输出 #2
1337
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted