QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#78493#5517. Adjacent Product SummikeacTL 22ms8780kbPython3664b2023-02-19 09:54:572023-02-19 09:54:57

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-19 09:54:57]
  • 评测
  • 测评结果:TL
  • 用时:22ms
  • 内存:8780kb
  • [2023-02-19 09:54:57]
  • 提交

answer

import collections
import math
import random
import sys
from functools import *
from heapq import *

input = lambda: sys.stdin.readline().rstrip("\r\n")
ints = lambda: list(map(int, input().split()))

# MOD = 998244353
# MOD = 10 ** 9 + 7

def solve() -> None:
    n = int(input())
    arr = ints()
    
    arr.sort(reverse=True)
    res = collections.deque([])
    for i in range(n):
        if i % 2 == 1:
            res.append(arr[i])
        else:
            res.appendleft(arr[i])
    ans = res[0]*res[-1]
    for i in range(n-1):
        ans += res[i]*res[i+1]
    print(ans)

t = int(input())
for _ in range(t):
    solve()

详细

Test #1:

score: 100
Accepted
time: 22ms
memory: 8780kb

input:

4
3
1 2 3
6
1 1 1 1 0 0
5
100000 100000 100000 100000 -100000
5
1 2 3 4 5

output:

11
3
10000000000
48

result:

ok 4 number(s): "11 3 10000000000 48"

Test #2:

score: -100
Time Limit Exceeded

input:

1
200000
11009 633591 -419208 -664908 731171 -774644 -878270 656078 -38057 -220602 -897906 670165 -765931 -612936 -583782 -549624 -644245 137209 -983054 -110583 349193 699723 -412876 -417691 810865 -474314 -200632 570810 -283481 39600 20940 218215 -408751 -507326 -961614 600863 499517 -538207 767155...

output:


result: