QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99422#6318. Magical WalletGeorge_Plover#AC ✓13ms8744kbC++231.5kb2023-04-22 13:24:072023-04-22 13:24:08

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.
  • [2023-04-22 13:24:08]
  • Judged
  • Verdict: AC
  • Time: 13ms
  • Memory: 8744kb
  • [2023-04-22 13:24:07]
  • Submitted

answer

#include <set>
#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 110
#define MAXM 11000
#define vint vector<int> 

using namespace std;
int n,m;
int a[MAXN];
int belong[MAXM];
int cnt;
map<vint,int> S;
vint vec[MAXM];

int Belong(int x){
    int y=x;
    if(belong[x])return belong[x];
    vint t;
    while(x){
        t.push_back(x%10);
        x/=10;
    }
    sort(t.begin(),t.end());
    if(S.count(t)){
        belong[y]=S[t];
    }
    else{
        belong[y]=S[t]=++cnt;
    }
    vec[belong[y]].push_back(y);
    return belong[y];
}

int dp[MAXN][MAXM];

int main(){

    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);

    for(int i=0;i<=10000;i++){
        Belong(i);
    }

    // for(auto &v:vec[Belong(m)]){
    //     cout<<v<<" ";
    // }cout<<endl;
    
    //cout<<Belong(120)<<endl;
    for(int i=0;i<MAXN;i++)
        for(int j=0;j<MAXM;j++)
            dp[i][j]=-MAXM;
    for(int i=1;i<=cnt;i++){
        if(i==Belong(m)){
            dp[0][i] = 0;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=cnt;j++){
            for(auto &v: vec[j]){
                if(v>=a[i]){
                    dp[i][Belong(v-a[i])]=max(dp[i][Belong(v-a[i])],dp[i-1][j]+1);
                }
            }
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
        }
    }
    int ans=0;
    for(int i=1;i<=cnt;i++){
        ans=max(ans,dp[n][i]);
    }
    cout<<ans<<endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 8716kb

input:

2 120
142 90

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 6ms
memory: 8740kb

input:

1 119
911

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 6ms
memory: 8732kb

input:

5 1000
900 90 900 9 900

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 0
Accepted
time: 7ms
memory: 8656kb

input:

7 1171
6328 2419 8302 7503 1744 8495 1522

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 11ms
memory: 8612kb

input:

100 7397
1321 3858 2112 3550 3306 7971 5835 8453 3563 9634 6018 316 5373 3548 3255 9106 8540 1011 9960 755 5424 2007 7158 7557 3167 7485 7846 4662 6228 1009 8198 6004 3756 4076 8175 2631 6689 4477 9682 8879 7600 3552 6042 7300 5424 1763 129 2515 6311 9880 7683 2664 2625 4751 5798 9865 1877 3481 9 81...

output:

89

result:

ok 1 number(s): "89"

Test #6:

score: 0
Accepted
time: 2ms
memory: 8676kb

input:

100 875
4476 1186 173 4759 7577 9793 2743 2033 2903 9188 2902 1040 988 6335 4933 5897 6083 7661 9376 6751 3495 3211 6750 681 1228 8515 9324 8960 528 7521 1269 6008 2502 3867 1377 7712 8973 5486 6355 6686 9651 5156 5021 6899 7614 6944 7195 9270 6984 5274 3752 3835 9018 1764 8404 9843 5948 8590 8052 1...

output:

7

result:

ok 1 number(s): "7"

Test #7:

score: 0
Accepted
time: 2ms
memory: 8736kb

input:

100 8928
9311 8786 3257 1458 4427 1576 1998 5838 5708 4764 9637 9446 1323 3140 2427 5994 254 5515 7516 4655 8232 5578 9511 6530 1314 1027 6515 7642 5571 3348 6791 4537 4443 7032 39 1821 3542 4789 2544 6660 6045 5080 4580 8980 4965 9296 812 4738 1704 4783 5691 3512 8108 1665 696 5196 2961 2366 5769 9...

output:

89

result:

ok 1 number(s): "89"

Test #8:

score: 0
Accepted
time: 7ms
memory: 8720kb

input:

100 4004
7075 2382 8197 4755 7696 6248 8573 2708 9344 256 3883 2436 3715 3691 9796 1014 2589 5434 3971 6266 3577 9396 5135 449 8665 3812 5110 6661 1516 1964 2894 3407 7606 3029 7026 2330 7561 4160 1379 1974 918 6537 4455 553 9195 1205 9703 4393 7950 637 5796 7688 3156 4029 5365 521 9052 3330 3381 42...

output:

87

result:

ok 1 number(s): "87"

Test #9:

score: 0
Accepted
time: 8ms
memory: 8728kb

input:

100 4096
720 2280 6511 9537 6453 6902 1011 6186 7364 9941 7937 1571 2159 4059 2669 8180 7821 1416 3011 4748 7214 2159 8748 2718 2715 4830 8426 1324 6397 4881 454 3819 833 8517 5716 1409 9478 3162 3451 232 8268 4672 7706 7824 1045 835 2161 5755 2802 4064 2967 7239 4865 5808 2698 1193 3287 1413 8222 1...

output:

92

result:

ok 1 number(s): "92"

Test #10:

score: 0
Accepted
time: 12ms
memory: 8620kb

input:

100 5548
5362 8804 7972 893 6985 4246 368 4538 9070 7286 2167 1790 1636 5687 3443 3550 6632 508 7892 5796 7491 1649 8392 9841 8460 228 4700 200 1705 5880 2834 8892 4896 5645 5485 8366 3879 2620 1799 1155 4441 7679 2604 8608 7126 3872 2582 400 6500 8475 6219 3740 5814 360 1519 5692 9601 9405 1365 360...

output:

91

result:

ok 1 number(s): "91"

Test #11:

score: 0
Accepted
time: 8ms
memory: 8636kb

input:

100 6422
779 3140 34 9042 4162 6517 5473 857 8852 5967 64 9691 6231 6844 886 1455 3032 2396 5729 1021 7776 509 5262 2598 3369 406 7810 7578 5379 5030 1034 2073 8139 5869 9836 872 6578 7737 3993 24 7565 1086 1702 9505 9160 5769 2614 7133 9685 3173 2916 458 6068 378 9979 3613 3937 4098 356 1751 5263 7...

output:

88

result:

ok 1 number(s): "88"

Test #12:

score: 0
Accepted
time: 11ms
memory: 8616kb

input:

52 2186
161 5873 6 659 3335 166 53 4577 8 3779 584 5739 8376 159 8516 974 7239 846 2 6 1738 8 52 67 6 4 6 95 28 538 803 4987 7 66 964 2836 733 4 8441 9159 91 370 88 4 9433 684 7517 8 9566 424 2 411

output:

50

result:

ok 1 number(s): "50"

Test #13:

score: 0
Accepted
time: 9ms
memory: 8728kb

input:

98 9
145 524 4992 2416 7781 631 4975 614 17 459 302 54 1622 9 2722 79 2876 328 87 16 7312 4962 9788 37 470 39 69 44 549 1137 67 24 85 12 25 5 34 1094 73 7575 3705 870 683 26 27 75 9 3151 6 151 6 96 702 3 16 32 4 620 6 5 462 8975 848 83 154 378 659 712 98 9 9182 87 97 3710 8135 8 57 60 4488 25 1559 9...

output:

3

result:

ok 1 number(s): "3"

Test #14:

score: 0
Accepted
time: 13ms
memory: 8652kb

input:

88 4414
1198 756 9320 426 294 9962 40 17 356 733 2 722 1392 1298 37 7 4 98 91 86 5119 640 65 9 71 474 5637 4898 62 6749 1 1899 279 98 49 43 125 8711 317 4 85 4 3 5 2948 7 216 4 8540 909 32 943 7385 689 1 92 541 31 2 459 9569 9669 417 57 9 1448 1 10 9568 451 8 82 1261 902 2643 5052 32 54 41 167 52 46...

output:

81

result:

ok 1 number(s): "81"

Test #15:

score: 0
Accepted
time: 11ms
memory: 8720kb

input:

50 496
388 858 504 932 24 73 452 69 1 4 9206 65 3858 286 2 89 1 9 9 44 362 2 625 78 65 3128 3 86 7845 576 3012 26 92 596 390 97 3 9 2597 955 958 1861 751 8307 456 584 4 3 4 69

output:

38

result:

ok 1 number(s): "38"

Test #16:

score: 0
Accepted
time: 5ms
memory: 8640kb

input:

22 9704
6 1886 3223 1557 3919 4 3973 4072 379 9369 849 596 16 31 48 6 37 733 6 5667 496 12

output:

21

result:

ok 1 number(s): "21"

Test #17:

score: 0
Accepted
time: 7ms
memory: 8680kb

input:

9 8238
4141 3827 2699 6705 3916 355 4763 3630 8636

output:

9

result:

ok 1 number(s): "9"

Test #18:

score: 0
Accepted
time: 2ms
memory: 8732kb

input:

56 311
4157 560 7083 8135 9248 5658 9684 8808 9462 534 6510 9601 1485 4500 6601 1551 9563 4210 4138 6234 1176 7127 792 5788 1809 7210 1697 8867 7286 4486 9178 3025 5045 6261 1160 4293 3501 2426 4683 2963 2959 1193 2564 4444 7275 9165 5994 6838 4957 1714 4654 7714 423 7027 3502 2232

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 5ms
memory: 8744kb

input:

91 4856
2616 9881 1129 450 3089 2326 7847 48 8009 5357 2020 3071 9963 9383 3750 9038 1731 3223 5173 2080 5821 4764 181 1070 7502 2660 9710 5918 310 5926 774 2925 5807 1902 4957 479 5809 4386 526 3819 9742 4127 8471 1288 3511 2221 1908 6823 5444 7080 8902 2847 3426 9083 3917 928 3325 5209 6846 3635 1...

output:

80

result:

ok 1 number(s): "80"