/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 17ms 564.0 KiB
#3 Accepted 16ms 568.0 KiB
#4 Accepted 11ms 580.0 KiB
#5 Accepted 12ms 532.0 KiB
#6 Accepted 14ms 532.0 KiB
#7 Accepted 9ms 788.0 KiB
#8 Accepted 4ms 772.0 KiB
#9 Accepted 6ms 1.066 MiB
#10 Accepted 7ms 1.07 MiB
#11 Accepted 9ms 1.02 MiB
#12 Accepted 10ms 836.0 KiB
#13 Accepted 11ms 832.0 KiB
#14 Accepted 11ms 776.0 KiB
#15 Accepted 11ms 1.02 MiB
#16 Accepted 10ms 836.0 KiB
#17 Accepted 11ms 1.02 MiB
#18 Accepted 11ms 1.023 MiB
#19 Accepted 31ms 532.0 KiB
#20 Accepted 20ms 572.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
#define vv vector<long long>
#define dq deque<long long>
#define mpp map<long long,long long>
#define ms multiset<long long>
#define ss set<long long>
#define vpp vector<pair<long long, long long>>
#define MOD 1000000007
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define all(a) a.begin(),a.end()
#define sort_rev(a) sort(a.rbegin(),a.rend())
#define all_n for(int i=0;i<n;i++)
#define print(a) for(auto it:a)cout<<it<<" "
#define print_pair(a) for(auto it:a)cout<<it.first<<" "<<it.second<<endl
#define scan(a,n) for(int i=0;i<n;i++)cin>>a[i]
void requisite(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
}
void solve(){
    ll n;cin>>n;
    vv v(n);
    scan(v,n);
    sort(all(v));
    mpp mp;
    ll count=0;
    vv a;
    for (int i = 0; i < n; ++i) {
        mp[v[i]]++;
    }
    while (mp.count(-1) and mp.count(1) and mp[-1] >= 2 and mp[1] > 0){
        mp[-1]-=2;
        mp[1]--;
        count++;
    }
     for(auto it:mp){
         for (int i = 0; i < it.second; ++i) {
             a.push_back(it.first);
         }
     }
    if (mp[1]==0) {
        ll i = 0;
        ll j = a.size() - 1;
        while (i < j) {
            count += (a[i] * a[i + 1] * a[j]);
            i += 2;
            j--;
        }
    }
    else{
        for (int i = 0; i < a.size(); i+=3) {
            count+=(a[i]*a[i+1]*a[i+2]);
        }
    }
    cout<<count<<endl;
}
int main() {
    requisite();
    ll t=1;
    cin>>t;
    while (t--){
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1152 Special Array
Contest
Happy New Year 2025
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 15:53:43
Judged At
2025-01-02 15:53:43
Judged By
Score
100
Total Time
31ms
Peak Memory
1.07 MiB