CF1895C.Torn Lucky Ticket

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A ticket is a non-empty string of digits from 11 to 99.

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 nn ticket pieces s1,s2,…,sns_1, s_2, \dots, s_n. How many pairs (i,j)(i, j) (for 1≤i,j≤n1 \le i, j \le n) are there such that si+sjs_i + s_j is a lucky ticket? Note that it's possible that i=ji=j.

Here, the + operator denotes the concatenation of the two strings. For example, if sis_i is 13, and sjs_j is 37, then si+sjs_i + s_j is 1337.

一张票是一个由数字 11 到 99 组成的非空字符串。

一张幸运票是满足以下条件的票:

  • 其长度为偶数;
  • 前一半数字之和等于后一半数字之和。

给定 nn 张票片段 s1,s2,…,sns_1, s_2, \dots, s_n。有多少对 (i,j)(i, j)(其中 1≤i,j≤n1 \le i, j \le n)满足 si+sjs_i + s_j 是一张幸运票?注意,i=ji = j 是允许的。

此处,++ 运算符表示两个字符串的拼接。例如,若 sis_i 为 13,sjs_j 为 37,则 si+sjs_i + s_j 为 1337。

输入格式

The first line contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of ticket pieces.

The second line contains nn non-empty strings s1,s2,…,sns_1, s_2, \dots, s_n, each of length at most 55 and consisting only of digits from 11 to 99.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示车票碎片的数量。

第二行包含 nn 个非空字符串 s1,s2,…,sns_1, s_2, \dots, s_n,每个字符串长度至多为 55,且仅由数字 11 到 99 组成。

输出格式

Print a single integer — the number of pairs (i,j)(i, j) (for 1≤i,j≤n1 \le i, j \le n) such that si+sjs_i + s_j is a lucky ticket.

输出一个整数——满足 si+sjs_i + s_j 是幸运车票的数对 (i,j)(i, j)(其中 1≤i,j≤n1 \le i, j \le n)的个数。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页