目录
一、题目
1、题目描述
2、输入输出
2.1输入
2.2输出
3、原题链接
二、解题报告
1、思路分析
拼接字符串长度为偶数
将输入字符串按照长度分组
我们枚举左边字符串长度i,右边字符串长度j
左边字符串只计算 [0, (i + j) / 2) 的正贡献,剩下的视为负贡献,记录在哈希表中
右边字符串类似
哈希计数即可
2、复杂度
时间复杂度: O(25N)空间复杂度:O(N)
3、代码详解
import sys
import math
import heapq
from collections import defaultdict, Counter
input = lambda: sys.stdin.readline().strip()
output = lambda x: sys.stdout.write(str(x) + '\n')
MII = lambda: map(int, input().split())
LMI = lambda: list(map(int, input().split()))
LI = lambda: list(input())
II = lambda: int(input())
I = lambda: input()
fmax = lambda x, y: x if x > y else y
fmin = lambda x, y: x if x < y else y
# sys.stdin = open('in.txt', 'r')
def solve():
n = II()
ss = input().split()
a = [[] for _ in range(6)]
for s in ss:
a[len(s)].append(s)
res = 0
for i in range(1, 6):
for j in range(1, 6):
if (i + j) & 1:
continue
m = (i + j) // 2
cnt = [0] * 100
for _, s in enumerate(a[i]):
val = 50
for k, c in enumerate(s):
if k < m:
val += int(c)
else:
val -= int(c)
cnt[val] += 1
for _, s in enumerate(a[j]):
val = 50
for k, c in enumerate(s):
if i + k < m:
val -= int(c)
else:
val += int(c)
res += cnt[val]
output(res)
pass
if __name__ == "__main__":
T = 1
# T = II()
for _ in range(T):
solve()