/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 512.0 KiB
#2 Time Exceeded ≥2092ms ≥324.0 KiB
#3 Accepted 1366ms 324.0 KiB
#4 Time Exceeded ≥2090ms ≥324.0 KiB
#5 Accepted 168ms 532.0 KiB
#6 Time Exceeded ≥2083ms ≥320.0 KiB
#7 Time Exceeded ≥2065ms ≥324.0 KiB
#8 Time Exceeded ≥2096ms ≥532.0 KiB
#9 Time Exceeded ≥2084ms ≥532.0 KiB
#10 Time Exceeded ≥2094ms ≥532.0 KiB
#11 Time Exceeded ≥2087ms ≥324.0 KiB
#12 Time Exceeded ≥2084ms ≥320.0 KiB
#13 Time Exceeded ≥2078ms ≥532.0 KiB
#14 Time Exceeded ≥2082ms ≥532.0 KiB
#15 Time Exceeded ≥2091ms ≥908.0 KiB
#16 Time Exceeded ≥2034ms ≥900.0 KiB
#17 Time Exceeded ≥2050ms ≥2.242 MiB
#18 Time Exceeded ≥2094ms ≥320.0 KiB
#19 Time Exceeded ≥2086ms ≥968.0 KiB
#20 Time Exceeded ≥2086ms ≥964.0 KiB
#21 Time Exceeded ≥2083ms ≥984.0 KiB
#22 Time Exceeded ≥2079ms ≥968.0 KiB
#23 Time Exceeded ≥2085ms ≥976.0 KiB
#24 Time Exceeded ≥2086ms ≥980.0 KiB
#25 Time Exceeded ≥2077ms ≥988.0 KiB
#26 Time Exceeded ≥2093ms ≥984.0 KiB
#27 Time Exceeded ≥2094ms ≥996.0 KiB
#28 Time Exceeded ≥2084ms ≥1004.0 KiB
#29 Time Exceeded ≥2078ms ≥320.0 KiB
#30 Time Exceeded ≥2097ms ≥2.008 MiB
#31 Time Exceeded ≥2091ms ≥2.023 MiB
#32 Time Exceeded ≥2093ms ≥532.0 KiB
#33 Time Exceeded ≥2087ms ≥2.016 MiB
#34 Time Exceeded ≥2088ms ≥900.0 KiB
#35 Time Exceeded ≥2089ms ≥2.02 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define Yes cout<<"Yes"<<"\n";
#define No  cout<<"No"<<"\n"; 
int gcdArray(const vector<int>& arr) {
    return accumulate(all(arr), arr[0], [](int a, int b) { return __gcd(a, b); });
}
int maxGCDSum(vector<int>& A) {
    int n = A.size();
    vector<int> indices(n);
    iota(all(indices), 0);
    int maxSum = 0;
    do {
        vector<int> oddIndexed, evenIndexed;
        for (int i = 0; i < n;i++) {
            if (i % 2 == 0) {
                evenIndexed.push_back(A[indices[i]]);
            } else {
                oddIndexed.push_back(A[indices[i]]);
            }
        }
        int oddGCD = gcdArray(oddIndexed);
        int evenGCD = gcdArray(evenIndexed);
        maxSum = max(maxSum, oddGCD + evenGCD);
    } while (next_permutation(all(indices)));
    return maxSum;
}
int main() {
    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        vector<int> A(N);
        for (int i = 0; i < N; i++) {
            cin >> A[i];
        }
        cout << maxGCDSum(A) <<nl;
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1077 Even Odd GCD (Hard Version)
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:22:36
Judged At
2024-10-03 13:27:13
Judged By
Score
7
Total Time
≥2097ms
Peak Memory
≥2.242 MiB