QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317526#7567. Joining Catsikaurov#ML 1ms7876kbC++171.7kb2024-01-29 04:11:072024-01-29 04:11:08

Judging History

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

  • [2024-01-29 04:11:08]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:7876kb
  • [2024-01-29 04:11:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define all(arr) (arr).begin(), (arr).end()
#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define endl '\n'

const int N = 5005;

int maxstart[N][N], maxend[N][N]; // [fan][index]
int dp[N][N]; // max last fan used

int w[N], s[N];

signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // cout.precision(20);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> w[i];
  for (int i = 0; i < k; i++) cin >> s[i];
  for (int fan = 0; fan < k; fan++){
    int curs = s[fan];
    for (int l = 0, r = -1, sum = 0; l < n; sum = max(0, sum - w[l]), l++){
      r = max(r, l - 1);
      while (r + 1 < n && sum + w[r + 1] <= curs){
        sum += w[++r];
      }
      maxstart[fan][l] = r + 1;
    }
  }
  reverse(w, w + n);
  for (int fan = 0; fan < k; fan++){
    int curs = s[fan];
    for (int l = 0, r = -1, sum = 0; l < n; sum = max(0, sum - w[l]), l++){
      r = max(r, l - 1);
      while (r + 1 < n && sum + w[r + 1] <= curs){
        sum += w[++r];
      }
      maxend[fan][l] = r + 1;
    }
  }

  for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = -1;
  dp[0][0] = k;
  for (int l = 0; l <= n; l++){
    for (int r = 0; r <= n; r++){
      if (dp[l][r] == -1) continue;
      if (l + r >= n - 1){
        cout << "Yes" << endl;
        return 0;
      }
      if (dp[l][r] == 0) continue;
      int fan = dp[l][r] - 1;
      dp[maxstart[fan][l]][r] = max(dp[maxstart[fan][l]][r], fan);
      dp[l][maxend[fan][r]] = max(dp[l][maxend[fan][r]], fan);
    }
  }
  cout << "No" << endl;
}

詳細信息

Test #1:

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

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

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: 1ms
memory: 7744kb

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

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Memory Limit Exceeded

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: