QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#54006#2544. Flatland CurrencyCtrl2333WA 26ms4144kbC++2.2kb2022-10-06 16:41:492022-10-06 16:41:52

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-06 16:41:52]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:4144kb
  • [2022-10-06 16:41:49]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
LL n,X,a[100100],cnt[5],ret[5][100100],fin[5];
LL sum[5][100100];
struct Node{
    LL val;
    int id;
    bool operator <(const Node &A) const{
        if (A.val!=val) return val<A.val;
        return id>A.id;
    }
}all[100100];
int num;
void glue(){
    for(int i=1;i+11<=cnt[1];i+=12){
        LL now=0;
        for(int j=0;j<=11;j++) now+=ret[1][i+j];
        all[++num].val=now;
        all[num].id=1;
    }

    for(int i=1;i+5<=cnt[2];i+=6){
        LL now=0;
        for(int j=0;j<=5;j++) now+=ret[2][i+j];
        all[++num].val=now;
        all[num].id=2;
    }
    for(int i=1;i+3<=cnt[3];i+=4){
        LL now=0;
        for(int j=0;j<=3;j++) now+=ret[3][i+j];
        all[++num].val=now;
        all[num].id=3;
    }
    for(int i=1;i+2<=cnt[4];i+=3){
        LL now=0;
        for(int j=0;j<=2;j++) now+=ret[4][i+j];
        all[++num].val=now;
        all[num].id=4;
    }
}
LL judge(LL W,LL V){
    LL mx=W;
    V-=(sum[1][fin[1]]+sum[2][fin[2]]+sum[3][fin[3]]+sum[4][fin[4]]);
    LL newV,newW;
    for(int l1=fin[1];l1<=min(cnt[1],fin[1]+11);l1++)
    for(int l2=fin[2];l2<=min(cnt[2],fin[2]+5);l2++)
    for(int l3=fin[3];l3<=min(cnt[3],fin[3]+3);l3++)
    for(int l4=fin[4];l4<=min(cnt[4],fin[4]+2);l4++){
        newV=V;
        newV+=sum[1][l1]+sum[2][l2]+sum[3][l3]+sum[4][l4];
        if (newV<=X){
            mx=max(mx,W+l1-fin[1]+2*(l2-fin[2])+3*(l3-fin[3])+4*(l4-fin[4]));
        }
    }
    return mx;
}
int main()
{
    scanf("%lld%lld",&n,&X);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        LL p=(5-a[i]%5)%5;
        cnt[p]++;
        ret[p][cnt[p]]=a[i]+p;
    }
    for(int i=1;i<=4;i++) sort(ret[i]+1,ret[i]+cnt[i]+1);
    LL ans=X%5;
    X-=ans;
    glue();
    for(int i=1;i<=4;i++){
        for(int j=1;j<=cnt[i];j++) sum[i][j]=sum[i][j-1]+ret[i][j];
    }
    LL nowW=ans,nowV=0;
    ans=max(ans,judge(nowW,nowV));
    for(int i=1;i<=num;i++){
        nowW+=12; nowV+=all[i].val;
        fin[all[i].id]+=12/all[i].id;
        if (nowV>X) break;
        ans=max(ans,judge(nowW,nowV));
    }
    printf("%lld",ans);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 1720kb

input:

5 57
9 14 31 18 27

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 1836kb

input:

4 50
11 11 11 11

output:

12

result:

ok answer is '12'

Test #3:

score: 0
Accepted
time: 26ms
memory: 4124kb

input:

100000 89648823509660
921733427 402270498 51157221 585477094 435728758 913951087 580580944 557082810 585086423 837912728 799129405 867009344 751591136 714946046 464999915 256043168 416678301 183246216 569365122 479031618 435168577 31068363 903791719 497652990 960987871 223120213 395437892 112869678 ...

output:

200414

result:

ok answer is '200414'

Test #4:

score: -100
Wrong Answer
time: 25ms
memory: 4144kb

input:

99999 3234700062922
394766137 401419056 55997758 205712163 585962152 750591556 245421581 607883471 437707305 758188075 522354844 202404802 307099733 99935245 321784033 643800024 481548024 43007287 404431495 848761213 352455926 541535791 702868758 875691279 485597478 119612707 776231855 48839061 1144...

output:

11364

result:

wrong answer expected '61505', found '11364'