/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Time Exceeded ≥2096ms ≥560.0 KiB
#3 Time Exceeded ≥2096ms ≥332.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define nl "\n"
#define pb push_back
#define pB pop_back
#define optimize()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
typedef long long ll;
const int mod = 1e9+7;
void solve()
{
    int n,m; cin>>n>>m;
    int a[n], ans=INT_MAX;
    for(int i=0; i<n; i++) cin>>a[i];
    for(int i=0; i<(1<<n); i++)
    {
        int d=0,cnt=0;
        for(int k=0; k<n; k++)
        {
            if((i>>k)&1)
            {
                d+=a[k];
                cnt++;
            }
        }
        if(cnt==m)
        {
            ans=min(ans,d);
        }
    }
    cout<<ans<<nl;
}
int main()
{
    optimize();
    int t;
    cin>>t;
    //t=1;
    while(t--)
    {
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1149 Swap and Minimize
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-10 17:24:57
Judged At
2024-12-10 17:24:57
Judged By
Score
1
Total Time
≥2096ms
Peak Memory
≥560.0 KiB