/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 484.0 KiB
#2 Accepted 9ms 1.461 MiB
#3 Accepted 10ms 1.609 MiB
#4 Accepted 10ms 1.445 MiB
#5 Accepted 11ms 1.625 MiB
#6 Accepted 14ms 1.438 MiB
#7 Accepted 15ms 1.465 MiB
#8 Accepted 17ms 1.684 MiB
#9 Accepted 17ms 1.637 MiB
#10 Accepted 18ms 1.559 MiB
#11 Accepted 19ms 1.664 MiB
#12 Accepted 19ms 1.672 MiB
#13 Accepted 17ms 1.777 MiB
#14 Accepted 21ms 1.688 MiB
#15 Accepted 23ms 1.68 MiB
#16 Accepted 27ms 1.777 MiB
#17 Accepted 98ms 900.0 KiB
#18 Accepted 843ms 712.0 KiB

Code

#include <bits/stdc++.h>
 
typedef long long ll;
using namespace std;

const int N=1e6+5;
int loss[N];

void solve(){

    int bridge = 4;
    int n,k; cin>>n>>k;

    vector<ll> v;
    //memset(loss, 0, sizeof(loss));
    int choice = 1;
    
    ll sum = 0;
    for(int i=0; i<n; i++){
        ll x; cin>>x;
        v.push_back(x);
        loss[x]+=1;
        sum+=x;
    }

    //cout<<sum<<"\n";

    for(int i=2 ; i<=min<ll>(bridge, k); i++){
        ll ans =0;
        for(auto x: v){
            if(x%i == 0) ans+=x;
        }
        if(ans<sum) {
            choice = i;
            sum = ans;
        }
    }

    for(int i=bridge+1; i<=k; i++){
        ll ans = 0;
        for(int j = i; j<=1e6; j+=i){
            ans+= 1LL*j*loss[j];
        }

        if(ans<sum) {
            choice = i;
            sum = ans;
        }
    }

    cout<<choice<<"\n";

    for(auto x: v) loss[x] = 0; 
    

    return;

}

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t; cin>>t;

    while(t--){
        solve();
    }

    return 0;

}
 

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Contest
Brain Booster #3
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-06 16:21:41
Judged At
2024-11-11 03:33:12
Judged By
Score
100
Total Time
843ms
Peak Memory
1.777 MiB