/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 16ms 3.105 MiB
#2 Wrong Answer 15ms 3.004 MiB
#3 Wrong Answer 16ms 3.141 MiB
#4 Wrong Answer 16ms 3.172 MiB
#5 Wrong Answer 15ms 3.117 MiB
#6 Wrong Answer 15ms 2.941 MiB
#7 Wrong Answer 15ms 3.109 MiB
#8 Wrong Answer 15ms 2.953 MiB
#9 Wrong Answer 16ms 3.07 MiB
#10 Wrong Answer 16ms 3.152 MiB
#11 Wrong Answer 16ms 3.184 MiB
#12 Wrong Answer 16ms 3.062 MiB
#13 Wrong Answer 16ms 3.062 MiB
#14 Wrong Answer 16ms 3.184 MiB
#15 Wrong Answer 16ms 3.137 MiB
#16 Wrong Answer 16ms 3.133 MiB
#17 Wrong Answer 16ms 3.176 MiB
#18 Wrong Answer 17ms 3.004 MiB
#19 Wrong Answer 17ms 3.145 MiB

Code

from math import gcd
from itertools import permutations

def calculate_gcd_of_list(lst):
    if len(lst) == 0:
        return 0
    current_gcd = lst[0]
    for num in lst[1:]:
        current_gcd = gcd(current_gcd, num)
    return current_gcd

def max_gcd_sum(N, A):
    max_sum = 0
    all_permutations = permutations(A)
    
    for perm in all_permutations:
        odd_indices = perm[0:N:2]
        even_indices = perm[1:N:2]
        X = calculate_gcd_of_list(odd_indices)
        Y = calculate_gcd_of_list(even_indices)
        max_sum = max(max_sum, X + Y)
    
    return max_sum

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    index = 0
    T = int(data[index])
    index += 1
    results = []
    
    for _ in range(T):
        N = int(data[index])
        index += 1
        A = list(map(int, data[index:index + N]))
        index += N
        results.append(max_gcd_sum(N, A))
    
    for result in results:
        print(result)

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:24:47
Judged At
2024-10-03 13:27:03
Judged By
Score
0
Total Time
17ms
Peak Memory
3.184 MiB