QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#144656#3206. Acperiencesomeaccaccount0 0ms0kbPython3397b2023-08-21 17:30:572023-08-21 17:30:57

Judging History

This is the latest submission verdict.

  • [2023-08-21 17:30:57]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2023-08-21 17:30:57]
  • Submitted

answer

from fractions import Fraction

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    
    s = 0
    for i in arr:
        s += abs(i)
    s = Fraction(s, n)
    
    ans = 0
    for i in arr:
        if i >= 0:
            ans += (i - s) ** 2
        else:
            ans += (i + s) ** 2
    print(f'{ans.numerator}/{ans.denominator}')

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

393
4
1 2 3 4
4
2 2 2 2
5
5 6 2 3 4
10
0 0 1 -1 -1 1 -1 1 -1 -1
10
-1 -1 -1 1 1 0 1 -1 -1 1
10
1 1 0 -1 0 1 0 1 -1 -1
10
0 0 0 1 -1 -1 1 1 1 1
10
-1 1 -1 -1 1 0 1 -1 -1 0
10
1 1 0 -1 1 -1 -1 -1 0 1
10
1 0 1 1 -1 -1 0 0 0 -1
10
-1 1 -1 -1 0 0 -1 1 1 1
10
0 -1 -1 0 -1 0 1 1 1 0
10
0 1 1 0 1 0 -1 1 1 1...

output:

5/1
0/1
10/1
8/5
9/10
21/10
21/10
8/5
8/5
12/5
8/5
12/5
21/10
12/5
5/2
21/10
21/10
21/10
8/5
21/10
21/10
5/2
12/5
12/5
12/5
5/2
12/5
12/5
8/5
12/5
5/2
21/10
21/10
21/10
21/10
12/5
9/10
8/5
9/10
12/5
21/10
8/5
12/5
21/10
9/10
5/2
5/2
12/5
21/10
21/10
21/10
21/10
21/10
12/5
5/2
12/5
8/5
8/5
21/10
21/1...

result: