/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Time Exceeded ≥1086ms ≥764.0 KiB
#3 Time Exceeded ≥1082ms ≥536.0 KiB
#4 Time Exceeded ≥1092ms ≥320.0 KiB
#5 Time Exceeded ≥1086ms ≥532.0 KiB
#6 Time Exceeded ≥1094ms ≥324.0 KiB
#7 Time Exceeded ≥1091ms ≥488.0 KiB
#8 Time Exceeded ≥1098ms ≥552.0 KiB
#9 Time Exceeded ≥1091ms ≥320.0 KiB
#10 Time Exceeded ≥1090ms ≥324.0 KiB
#11 Time Exceeded ≥1091ms ≥484.0 KiB
#12 Time Exceeded ≥1085ms ≥536.0 KiB
#13 Time Exceeded ≥1082ms ≥372.0 KiB
#14 Time Exceeded ≥1078ms ≥532.0 KiB
#15 Time Exceeded ≥1089ms ≥324.0 KiB
#16 Time Exceeded ≥1079ms ≥324.0 KiB
#17 Time Exceeded ≥1091ms ≥324.0 KiB
#18 Time Exceeded ≥1094ms ≥344.0 KiB
#19 Time Exceeded ≥1089ms ≥320.0 KiB

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
P1076 Even Odd GCD (Easy Version)
Contest
Bangladesh 2.0
Language
C++17 (G++ 13.2.0)
Submit At
2024-08-16 16:17:24
Judged At
2024-10-03 13:27:43
Judged By
Score
1
Total Time
≥1098ms
Peak Memory
≥764.0 KiB