QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214855#7567. Joining CatsTheOneYouWant#WA 8ms30260kbC++142.0kb2023-10-15 00:33:412023-10-15 00:33:41

Judging History

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

  • [2023-10-15 00:33:41]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:30260kb
  • [2023-10-15 00:33:41]
  • 提交

answer

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

#define int long long int
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repb(i, a, b) for(int i = (a); i >= (b); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back

#define ln '\n'
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.ff<<","<<v.ss<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    for(auto &x : c) out<<x<<" ";
    out<<"}"; return out;
}

const int MOD = 1e9+7, LIM = 3e5+5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

struct interval{
	int l, r, pos;
};

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int tests = 1;
	// cin >> tests;

	while(tests--){
		cin >> n >> k;
		rep(i, 0, n) cin >> w[i];
		rep(i, 0, k) cin >> s[k-1-i];

		queue<interval> q;
		q.push({0, n-1, 0});

		bool done[n][n];
		rep(i,0,n) rep(j,0,n) done[i][j] = 0;

		bool pos = 0;

		while(!q.empty()){

			auto t = q.front();
			q.pop();
			if(t.l>=t.r){
				pos = 1;
				break;
			}
			if(done[t.l][t.r]) continue;
			if(t.pos==k) continue;
			done[t.l][t.r] = 1;
			// try left
			int lpos = t.l, pref = 0;
			while((lpos<=t.r)&&(pref+w[lpos]<=s[t.pos])){				
				pref += w[lpos];
				lpos++;
			}
			// lpos, t.r will be left
			q.push({lpos, t.r, t.pos+1});
			int rpos = t.r; pref = 0;
			while((rpos>=t.l)&&(pref+w[rpos]<=s[t.pos])){
				pref += w[rpos];
				rpos--;
			}
			q.push({t.l, rpos, t.pos+1});
		}

		if(pos) cout << "Yes" << ln;
		else cout << "No" << ln;

	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2
1 1 1 1 1
2 2

output:

Yes

result:

ok answer is YES

Test #2:

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

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

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

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 3ms
memory: 30260kb

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

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: 8ms
memory: 30116kb

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

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:

No

result:

wrong answer expected YES, found NO