/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 22ms 3.039 MiB
#2 Time Exceeded ≥1054ms ≥3.086 MiB
#3 Time Exceeded ≥1031ms ≥3.059 MiB
#4 Time Exceeded ≥1023ms ≥3.199 MiB
#5 Time Exceeded ≥1022ms ≥3.152 MiB
#6 Time Exceeded ≥1054ms ≥3.199 MiB
#7 Time Exceeded ≥1035ms ≥3.191 MiB
#8 Time Exceeded ≥1048ms ≥3.137 MiB
#9 Time Exceeded ≥1045ms ≥3.125 MiB
#10 Time Exceeded ≥1050ms ≥3.066 MiB
#11 Time Exceeded ≥1048ms ≥3.117 MiB
#12 Time Exceeded ≥1022ms ≥3.207 MiB
#13 Time Exceeded ≥1037ms ≥3.055 MiB
#14 Time Exceeded ≥1032ms ≥3.07 MiB
#15 Time Exceeded ≥1098ms ≥3.16 MiB
#16 Time Exceeded ≥1035ms ≥3.09 MiB
#17 Time Exceeded ≥1032ms ≥3.07 MiB
#18 Time Exceeded ≥1085ms ≥3.098 MiB
#19 Time Exceeded ≥1015ms ≥3.102 MiB

Code

from itertools import permutations
from math import gcd

def max_gcd_sum(arr):
    n = len(arr)
    max_sum = 0
    for perm in permutations(arr):
        odd_gcd = perm[0]
        even_gcd = perm[1]
        for i in range(2, n):
            if i % 2 == 0:
                even_gcd = gcd(even_gcd, perm[i])
            else:
                odd_gcd = gcd(odd_gcd, perm[i])
        max_sum = max(max_sum, odd_gcd + even_gcd)
    return max_sum

def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        arr = list(map(int, input().split()))
        print(max_gcd_sum(arr))

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1076 Even Odd GCD (Easy Version)
Contest
Bangladesh 2.0
Language
Python 3 (Python 3.12.3)
Submit At
2024-08-16 16:25:38
Judged At
2024-10-03 13:26:58
Judged By
Score
1
Total Time
≥1098ms
Peak Memory
≥3.207 MiB