QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#62088#2544. Flatland CurrencyWilson_LeeWA 2ms7616kbC++2.8kb2022-11-17 09:06:422022-11-17 09:06:44

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-17 09:06:44]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 7616kb
  • [2022-11-17 09:06:42]
  • Submitted

answer

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

typedef pair<long long,int>pa;
const int MAXN=1e5+5;
const long long INF=0x3f3f3f3f3f3f3f3f;
long long a[MAXN];
int b[MAXN],dp[2][MAXN<<2];
vector<long long>num[5];
int cnt[5];
bool cmp(pa x,pa y){return x.first==y.first?x.second>y.second:x.first<y.first;}
int main()
{
    //freopen("DD.in","r",stdin);
    //freopen("DD.out","w",stdout);
    int n;
    long long m;
    cin>>n>>m;
    int tmp=m%5;
    m-=tmp;
    if(!m)
    {
        printf("%d",tmp);
        return 0;
    }
    for(int i=1;i<=n;++i) scanf("%lld",&a[i]),b[i]=(a[i]%5==0)?0:(5-a[i]%5),a[i]+=b[i];
    for(int i=1;i<=n;++i)
    {
        if(!b[i]) continue;
        num[b[i]].push_back(a[i]);
    }
    for(int i=1;i<=4;++i) sort(num[i].begin(),num[i].end());
    for(int i=1;i<=4;++i)
    {
        int si=num[i].size();
        if(!si || num[i][0]>m) continue;
        bool flag=0;
        int sum=num[i][0];
        for(int j=1;j<si;++j)
        {
            sum+=num[i][j];
            if(sum>m)
            {
                flag=1;
                cnt[i]=j;
                break;
            }
        }
        if(!flag) cnt[i]=si;
    }
    memset(dp[0],0x3f,sizeof(dp[0]));
    dp[0][0]=0;
    int now=1,pre=0,prenum=0,val=0;
    for(int i=0;i<cnt[4];++i)
    {
        for(int j=0;j<=n*4;++j)
        {
            if(dp[pre][j]==INF) break;
            dp[now][j]=dp[pre][j];
            if(j>=val) dp[now][j]=min(dp[now][j],dp[pre][j-val]+prenum);
        }
        swap(now,pre),prenum=num[4][i],val=4;
    }
    for(int i=0;i<cnt[3];++i)
    {
        for(int j=0;j<=n*4;++j)
        {
            if(dp[pre][j]==INF) break;
            dp[now][j]=dp[pre][j];
            if(j>=val) dp[now][j]=min(dp[now][j],dp[pre][j-val]+prenum);
        }
        swap(now,pre),prenum=num[3][i],val=3;
    }
    for(int i=0;i<cnt[2];++i)
    {
        for(int j=0;j<=n*4;++j)
        {
            if(dp[pre][j]==INF) break;
            dp[now][j]=dp[pre][j];
            if(j>=val) dp[now][j]=min(dp[now][j],dp[pre][j-val]+prenum);
        }
        swap(now,pre),prenum=num[2][i],val=2;
    }
    for(int i=0;i<cnt[1];++i)
    {
        for(int j=0;j<=n*4;++j)
        {
            if(dp[pre][j]==INF) break;
            dp[now][j]=dp[pre][j];
            if(j>=val) dp[now][j]=min(dp[now][j],dp[pre][j-val]+prenum);
        }
        swap(now,pre),prenum=num[1][i],val=1;
    }
    for(int j=0;j<=n*4;++j)
    {
        if(dp[pre][j]==INF) break;
        dp[now][j]=dp[pre][j];
        if(j>=val) dp[now][j]=min(dp[now][j],dp[pre][j-val]+prenum);
    }
    int ans=0;
    for(int i=n*4;i>=0;--i)
    {
        if(dp[pre][i]<=m)
        {
            ans=i;
            break;
        }
    }
    ans+=tmp;
    cout<<ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5916kb

input:

5 57
9 14 31 18 27

output:

8

result:

ok answer is '8'

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 7616kb

input:

4 50
11 11 11 11

output:

8

result:

wrong answer expected '12', found '8'