QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204539#7567. Joining Catsucup-team1069#RE 95ms199848kbC++231.7kb2023-10-07 13:03:112023-10-07 13:03:11

Judging History

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

  • [2023-10-07 13:03:11]
  • 评测
  • 测评结果:RE
  • 用时:95ms
  • 内存:199848kb
  • [2023-10-07 13:03:11]
  • 提交

answer

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

const int N = 5012;

int n, k;
int w[N], s[N], dp[N][N];
short int goR[N][N], goL[N][N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);

    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i];
    }
    for (int i = 1; i <= k; ++i) {
        cin >> s[i];
    }
    reverse(s + 1, s + k + 1);
    vector<pair<int, int>> v;
    for (int i = 1; i <= k; ++i) {
        v.push_back({s[i], i});
    }
    sort(v.begin(), v.end());
    for (int i = 1; i <= n; ++i) {
        int pos = i - 1;
        long long W = 0;
        for (auto [x, j] : v) {
            while (pos + 1 <= n && W + w[pos + 1] <= x) {
                pos++;
                W += w[pos];
            }
            goR[i][j] = pos;
        }
    }
    for (int i = 1; i <= n; ++i) {
        int pos = i + 1;
        long long W = 0;
        for (auto [x, j] : v) {
            while (pos - 1 >= 1 && W + w[pos - 1] <= x) {
                pos--;
                W += w[pos];
            }
            goL[i][j] = pos;
        }
    }

    for (int i = 1; i <= k + 1; ++i) {
        for (int j = 1; j <= n + 1; ++j) {
            dp[i][j] = 10000;
        }
    }
    dp[1][1] = n;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (dp[i][j] == 10000) continue;
            dp[i + 1][goR[j][i] + 1] = min(dp[i + 1][goR[j][i] + 1], dp[i][j]);
            dp[i + 1][j] = min(dp[i + 1][j], goL[dp[i][j]][i] - 1);
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (dp[k + 1][i] <= i) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

詳細信息

Test #1:

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

input:

5 2
1 1 1 1 1
2 2

output:

Yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 7944kb

input:

6 7
3 2 1 1 2 3
2 2 2 2 2 2 2

output:

No

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 0ms
memory: 7728kb

input:

7 4
1 2 3 4 3 2 1
3 3 3 3

output:

Yes

result:

ok answer is YES

Test #4:

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

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 95ms
memory: 199848kb

input:

5000 5000
775487425 856128884 277783434 903422359 477267301 475103384 297595527 426167697 732858986 408894759 274205836 78265305 841664344 827278645 235744961 539622829 661053351 709331224 497285040 688977639 794889854 890450616 730989757 164925481 519732355 5132018 793806705 617096813 966338860 838...

output:

No

result:

ok answer is NO

Test #6:

score: 0
Accepted
time: 79ms
memory: 199820kb

input:

5000 5000
719129447 937392296 350445117 783330021 802155515 695380072 535475671 613171233 926763173 500405367 828284512 931492995 720877462 919465915 260912626 876806990 884762137 576596567 928561233 974405439 891740632 540536614 879167622 725668608 801467926 601260355 706621299 926987536 994204742 ...

output:

No

result:

ok answer is NO

Test #7:

score: 0
Accepted
time: 89ms
memory: 199848kb

input:

5000 5000
416747559 657602574 449451106 121890071 441124856 144632709 177533820 169507188 105623279 399624204 458468079 481561977 54065647 407303452 627276664 15195167 482406549 98222656 788603298 66301460 298650558 502696353 90244701 498415278 210561025 368288994 77615125 176971936 438514087 804772...

output:

No

result:

ok answer is NO

Test #8:

score: 0
Accepted
time: 23ms
memory: 125204kb

input:

1000 5000
652378395 9226710 369514617 603608037 161741291 783580574 951641399 734721388 223516311 671669592 479702806 414081589 624003108 605424248 896097938 156346340 669596794 597103379 732027711 334398013 586620215 764336953 962550397 952888036 385377097 271706418 466047181 667473147 451787252 34...

output:

Yes

result:

ok answer is YES

Test #9:

score: 0
Accepted
time: 20ms
memory: 125340kb

input:

1000 5000
872227273 712283986 920948311 507385120 918594985 900251115 743516868 670907467 867435817 714475407 652551933 758876839 384367533 880301180 841974114 886109922 903272749 893904997 942686977 997058175 645506447 529091876 716946215 871179658 785614131 908004811 934740746 911599923 901612611 ...

output:

Yes

result:

ok answer is YES

Test #10:

score: 0
Accepted
time: 28ms
memory: 122100kb

input:

1000 5000
101221549 613813024 32283618 57848367 218671138 83846718 546915747 208915568 65619698 104572490 576248450 591458709 44189059 290360076 189086077 191457437 54318230 363455304 196546244 548385206 78485380 617280233 259809060 837752521 143584483 370863408 173419156 323661623 35630081 19426238...

output:

Yes

result:

ok answer is YES

Test #11:

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

input:

5000 1000
384600324 423088534 580011180 18888296 867263085 174486497 579265523 677106522 109080438 243659201 879794825 2734387 317935969 351036145 597636151 139952929 616539853 427107451 467123241 455242831 725282652 898994059 618761912 184726542 957829503 458946364 808393477 865906485 986478739 254...

output:

No

result:

ok answer is NO

Test #12:

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

input:

5000 1000
815377947 795966497 973863440 950044920 825108167 536452850 291112961 631853166 506218010 935798593 775113558 699401829 880383613 914704745 782591416 917669693 708026290 459226993 668663128 910039920 841586352 784964960 888459540 302038322 659730234 805572069 846275367 852703409 775521351 ...

output:

No

result:

ok answer is NO

Test #13:

score: 0
Accepted
time: 24ms
memory: 123028kb

input:

5000 1000
5410336 393698641 500773894 760031044 646621826 839580211 65305975 201814752 180712432 120809208 163818904 82473446 457782197 21160078 17186078 215123683 176709095 456087785 326581971 310290921 168653566 481253103 321257970 84515932 243535065 236109465 60226866 102687808 41257836 127984905...

output:

No

result:

ok answer is NO

Test #14:

score: -100
Runtime Error

input:

5000 5000
15093311 329597379 555558975 156779227 62866262 160365196 114014190 248402694 204959438 271068381 399857257 387200774 160688159 271392845 128942838 158633588 10588789 191195688 113594413 649475911 58675835 141948582 145184928 141129342 341594247 628691612 444930099 62485843 137320414 79235...

output:


result: