/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 8ms 832.0 KiB
#3 Accepted 9ms 832.0 KiB
#4 Accepted 8ms 956.0 KiB
#5 Accepted 9ms 860.0 KiB
#6 Accepted 10ms 832.0 KiB
#7 Accepted 11ms 916.0 KiB
#8 Accepted 13ms 956.0 KiB
#9 Accepted 17ms 1000.0 KiB
#10 Accepted 31ms 1.383 MiB
#11 Accepted 77ms 2.418 MiB
#12 Accepted 63ms 2.324 MiB
#13 Accepted 51ms 2.359 MiB
#14 Accepted 83ms 2.438 MiB
#15 Accepted 90ms 2.43 MiB
#16 Accepted 105ms 2.43 MiB
#17 Accepted 541ms 2.09 MiB
#18 Time Exceeded ≥4072ms ≥1.816 MiB

Code

#include <bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
// #define int long long
#define all(x)      x.begin(),x.end()
#define allr(x)     x.rbegin(),x.rend()
#define CheckBit(x,k)   (x & (1LL << k))
#define SetBit(x,k)     (x |= (1LL << k))
#define ClearBit(x,k)   (x &= ~(1LL << k))
#define LSB(mask)       __builtin_ctzll(mask)
#define MSB(mask)       63-__builtin_clzll(mask) 
#define print(x)    cout << #x << " : " << x << endl
#define error1(x)   cerr << #x << " = " << (x) <<endl
#define coutall(v)  for(auto &it: v) cout<<it<<' '; cout<<endl
#define Abid_52     ios::sync_with_stdio(false);cin.tie(0),cin.tie(0)
#define error2(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n"
#define UNIQUE(x)   sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template <typename T, typename U> T ceil(T x, U y) {return (x > 0 ? (x + y - 1) / y : x / y);}
template <typename T, typename U> T floor(T x, U y) {return (x > 0 ? x / y : (x - y + 1) / y);}

const int N = 1e5 + 10;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    map<int,int>mp;
    int mx=INT_MIN;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        mx=max(mx,v[i]);
        mp[v[i]]++;
    }
    int mn=INT_MAX,ans=1;
    for(int i=1;i<=min(mx+1,m);i++)
    {
        ll cost=0;
        for(int j=i;j<=mx;j+=(i))
        {
            cost+=(mp[j]*j);
        }
        if(cost<mn)
        {
            mn=cost;
            ans=i;
        }
    }
    cout<<ans<<endl;
}

int32_t main()
{
    Abid_52;
    int t = 1;
    cin >> t;
    for (int tc = 1; tc <= t; ++tc)
    {
        // cout << "Case " << tc << ": ";
        solve();
    }
}

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-07 05:01:11
Judged At
2024-11-11 03:31:08
Judged By
Score
95
Total Time
≥4072ms
Peak Memory
≥2.438 MiB