Last active
July 7, 2021 16:52
-
-
Save uchidama/f6b37683aa9c3eaa5a43a7b9f08ae852 to your computer and use it in GitHub Desktop.
AtCoder Beginner Contest 177 [ C - Sum of product of pairs ] https://atcoder.jp/contests/abc177/tasks/abc177_c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
[問題] | |
https://atcoder.jp/contests/abc177/tasks/abc177_c | |
[解説] | |
https://youtu.be/D6dr2CrEgns?t=1154 | |
言われりゃ、そうかって感じだけど、この計算量減らしは、みんな気がついちゃうの? | |
むずくねー!? | |
''' | |
import sys | |
sys.setrecursionlimit(10 ** 6) # 再帰上限の引き上げ | |
input = sys.stdin.readline | |
INF = 2 ** 63 - 1 | |
N = int(input()) | |
A = list(map(int, input().split())) | |
SUM_A = sum(A) | |
TAIKAKU = 0 | |
for a in A: | |
TAIKAKU += a*a | |
# /2 だと計算誤差でWAでる。//2だとAC | |
ans = int( ( SUM_A * SUM_A - TAIKAKU ) // 2 % (10**9+7) ) | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment