A16333 | Torn Lucky Ticket
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A ticket is a non-empty string of digits from $1$ to $9$ .
A lucky ticket is such a ticket that:
- it has an even length;
- the sum of digits in the first half is equal to the sum of digits in the second half.
You are given $n$ ticket pieces $s_1, s_2, \dots, s_n$ . How many pairs $(i, j)$ (for $1 \le i, j \le n$ ) are there such that $s_i + s_j$ is a lucky ticket? Note that it's possible that $i=j$ .
Here, the + operator denotes the concatenation of the two strings. For example, if $s_i$ is 13, and $s_j$ is 37, then $s_i + s_j$ is 1337.
A lucky ticket is such a ticket that:
- it has an even length;
- the sum of digits in the first half is equal to the sum of digits in the second half.
You are given $n$ ticket pieces $s_1, s_2, \dots, s_n$ . How many pairs $(i, j)$ (for $1 \le i, j \le n$ ) are there such that $s_i + s_j$ is a lucky ticket? Note that it's possible that $i=j$ .
Here, the + operator denotes the concatenation of the two strings. For example, if $s_i$ is 13, and $s_j$ is 37, then $s_i + s_j$ is 1337.
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of ticket pieces.
The second line contains $n$ non-empty strings $s_1, s_2, \dots, s_n$ , each of length at most $5$ and consisting only of digits from $1$ to $9$ .
The second line contains $n$ non-empty strings $s_1, s_2, \dots, s_n$ , each of length at most $5$ and consisting only of digits from $1$ to $9$ .
输出格式
Print a single integer — the number of pairs $(i, j)$ (for $1 \le i, j \le n$ ) such that $s_i + s_j$ is a lucky ticket.
输入输出样例
输入 #1
10 5 93746 59 3746 593 746 5937 46 59374 6
输出 #1
20
输入 #2
5 2 22 222 2222 22222
输出 #2
13
输入 #3
3 1 1 1
输出 #3
9
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted