QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#208325#7567. Joining Catshos_lyricWA 154ms3740kbC++142.6kb2023-10-09 13:45:102023-10-09 13:45:11

Judging History

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

  • [2023-10-09 13:45:11]
  • 评测
  • 测评结果:WA
  • 用时:154ms
  • 内存:3740kb
  • [2023-10-09 13:45:10]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


int N, K;
vector<Int> W;
vector<Int> S;

int main() {
  for (; ~scanf("%d%d", &N, &K); ) {
    W.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%lld", &W[i]);
    }
    S.resize(K);
    for (int k = 0; k < K; ++k) {
      scanf("%lld", &S[k]);
    }
    
    vector<Int> WSum(N + 1, 0);
    for (int i = 0; i < N; ++i) {
      WSum[i + 1] = WSum[i] + W[i];
    }
    
    // l -> min r
    vector<int> crt(N + 1, N + 1);
    crt[0] = N;
    for (int k = K; --k >= 0; ) {
      vector<int> lr(N + 1), rl(N + 1);
      for (int l = 0, r = 0; l <= N; ++l) {
        for (; r + 1 <= N && WSum[r + 1] - WSum[l] <= S[k]; ++r) {}
        lr[l] = r;
      }
      for (int r = N, l = N; r >= N; --r) {
        for (; l - 1 >= 0 && WSum[r] - WSum[l - 1] <= S[k]; --l) {}
        rl[r] = l;
      }
      auto nxt = crt;
      for (int l = 0; l <= N; ++l) {
        const int r = crt[l];
        if (r <= N) {
          {
            int ll = lr[l];
            chmin(ll, r - 1);
            chmin(nxt[ll], r);
          }
          {
            int rr = rl[r];
            chmax(rr, l + 1);
            chmin(nxt[l], rr);
          }
        }
      }
      crt = nxt;
// cerr<<"nxt = "<<nxt<<endl;
    }
    
    bool ans = false;
    for (int l = 0; l < N; ++l) {
      ans = ans || (crt[l] <= l + 1);
    }
    puts(ans ? "Yes" : "No");
  }
  return 0;
}

详细

Test #1:

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

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

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

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

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Wrong Answer
time: 154ms
memory: 3740kb

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:

Yes

result:

wrong answer expected NO, found YES