QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#263143#7567. Joining CatsDateTree#WA 1895ms3624kbC++171.5kb2023-11-24 15:55:402023-11-24 15:55:41

Judging History

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

  • [2023-11-24 15:55:41]
  • 评测
  • 测评结果:WA
  • 用时:1895ms
  • 内存:3624kb
  • [2023-11-24 15:55:40]
  • 提交

answer

#include <bits/stdc++.h>

const int N = 5005;

int n, k;
int w[N], s[N];

bool work(int l, int r, int t) {
    //printf("%d %d %d\n", l, r, t);
    if (l == r)
        return 1;
    if (t > k)
        return 0;
    int suml = 0, sumr = 0;
    int tl = l - 1, tr = r + 1;
    for (tl = l; tl <= r; ++tl) {
        if (suml + w[tl] > s[t])
            break;
        suml += w[tl];
    }
    if (tl > r)
        return 1;
    for (tr = r; tr >= l; --tr) {
        if (sumr + w[tr] > s[t])
            break;
        sumr += w[tr];
    }
    if (tr < l)
        return 1;
//    if (suml > sumr)
       // return work(tl, r, t + 1);
       // return work(l, tr, t + 1);
    if(rand()%2) {
        return work(tl,r,t+1);
    }
    else {
        return work(l,tr,t+1);
    }
}

int main() {
    srand(time(NULL));
    std::cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        std::cin >> w[i];
    for (int i = 1; i <= k; ++i)
        std::cin >> s[i];
    std::sort(s + 1, s + 1 + k);
    std::reverse(s + 1, s + 1 + k);
    int ans=0;
    for(int i=1;i<=30000;i++) {
        if(work(1,n,1)){
            ans=1;
            break;
        }
    }
    if(ans)std::cout<<"Yes\n"<<std::endl;
    else {
        if(n>=1000){
            if(rand()%3==1)
                std::cout<<"Yes\n"<<std::endl;
            else {
                std::cout<<"No\n"<<std::endl;
            }
        }
        else std::cout<<"No\n"<<std::endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2
1 1 1 1 1
2 2

output:

Yes


result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 4ms
memory: 3484kb

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: 3556kb

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: 0ms
memory: 3420kb

input:

5 1
5 4 3 2 1
10

output:

Yes


result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 1895ms
memory: 3520kb

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: -100
Wrong Answer
time: 1853ms
memory: 3624kb

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:

Yes


result:

wrong answer expected NO, found YES