您的位置:首页 > Web前端

Educational Codeforces Round 34 (Rated for Div. 2) D. Almost Difference(高精度)

2017-12-13 16:39 483 查看
题目链接:http://codeforces.com/contest/903/problem/D

题目不难,按每个元素算贡献就好了,就是会爆long long,学习一下py的写法

代码:

from collections import Counter

n = input()
a = map(int, raw_input().split())
s = 0
c = Counter()
for i in xrange(n):
s += c[a[i] + 1] - c[a[i] - 1] + a[i] * (2 * i + 1 - n)
c[a[i]] += 1
print(s)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐