/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 14ms 1.316 MiB
#3 Accepted 14ms 1.309 MiB
#4 Wrong Answer 14ms 1.312 MiB
#5 Accepted 17ms 1.309 MiB
#6 Accepted 18ms 1.316 MiB
#7 Accepted 16ms 1.227 MiB
#8 Accepted 21ms 1.316 MiB
#9 Accepted 27ms 1.367 MiB
#10 Accepted 46ms 1.926 MiB
#11 Accepted 107ms 3.305 MiB
#12 Accepted 91ms 3.312 MiB
#13 Accepted 74ms 3.297 MiB
#14 Accepted 143ms 3.309 MiB
#15 Accepted 156ms 3.316 MiB
#16 Accepted 202ms 3.32 MiB
#17 Accepted 860ms 2.633 MiB
#18 Time Exceeded ≥4023ms ≥2.535 MiB

Code

// بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
// In the Name of Allah, the Beneficent, the Merciful.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define vi vector<int>
#define vl vector<long long>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define inv(a) for(auto &it : a) cin >> it;
#define outv(a) for(auto &it : a) cout << it << " ";cout<<"\n"
#define outv1(a) for(auto &it : a) cout << it << " "<<"\n";cout<<"\n"
#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define inf 1e9
// #define double long double
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define int long long

bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
    if(a.first==b.first) return a.second>b.second;
    return a.first < b.first;
}

int calc(int n) {
    return n*(n-1)/2;
}

void solve(int tc) {
    int n,k;
    cin>>n>>k;
    vl v(n);
    inv(v);
    int ma = *max_element(all(v));
    // if(ma+1<=k) {
    //     cout<<ma+1<<endl;
    //     return;
    // }
    map<int,int> mp;
    int ans = 1,mi=LONG_LONG_MAX;
    for (int i = 0; i < n; i++)
    {
        mp[v[i]]++;
    }
    
    for (int i = 2; i <= k; i++)
    {
        int c = 0;
        for (int j = i; j <= ma+10; j+=i)
        {
            if(mp[j]) c+=mp[j]*j;
        }
        // cout<<i<<" "<<c<<endl;
        if(c<mi) {
            mi = c;
            ans = i;
        }
        
    }
    cout<<ans<<endl;
    
    
}

int32_t main() {
    fastio;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    
    int tc=1;
    cin>>tc;
    for (int i = 1; i <= tc; i++)
    {
        solve(i);
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-08 09:56:04
Judged At
2024-11-11 03:30:33
Judged By
Score
90
Total Time
≥4023ms
Peak Memory
≥3.32 MiB