QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#699197#6769. Monster Hunterbeamishboys#TL 0ms3552kbC++23851b2024-11-02 04:55:132024-11-02 04:55:14

Judging History

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

  • [2024-11-02 04:55:14]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3552kb
  • [2024-11-02 04:55:13]
  • 提交

answer

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

void solve() {
	int n; cin >> n;
	vector<ll> a(n);
	for (ll &i : a) cin >> i;

	int m; cin >> m;
	vector<ll> h(m);
	for (ll &i : h) cin >> i;

	ll lb = 1, ub = 1e17;
	while (lb < ub-1) {
		ll m = (lb+ub)/2;

		ll cycle = m / a.size();
		ll one = cycle, two = cycle, three = cycle;
		for (int i = 0; i < m%a.size(); i++) {
			if (a[i] == 1) one += 1;
			if (a[i] == 2) two += 1;
			if (a[i] == 3) three += 1;
		}

		for (ll x : h) {
			ll useThree = min(three, x / 3);
			x -= useThree * 3;
			three -= useThree;
			ll useTwo = min(two, x / 2);
			two -= useTwo;
			x -= useTwo * 2;
			one -= x;
		}
		if (one >= 0) ub = m+1;
		else lb = m+1;
	}
	cout << lb << endl;
}

int main() {
	int t; cin >> t;
	while (t--) solve();
}

详细

Test #1:

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

input:

2
2
3 2
3
2 4 2
5
1 2 3 2 1
2
3 3

output:

4
3

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

100
21
1 3 3 3 2 3 3 2 2 1 3 2 1 3 2 1 1 1 3 3 3
3
3 3 1
19
1 3 1 1 3 3 1 3 2 3 2 2 3 3 1 1 2 2 2
10
2 2 3 1 5 2 2 5 5 3
8
1 3 3 1 3 2 3 1
3
1 2 1
27
1 1 1 2 1 3 1 2 2 3 3 3 1 1 1 1 2 1 2 2 2 2 3 2 1 3 2
4
5 1 2 2
23
2 1 3 2 3 2 2 3 1 2 1 3 1 2 3 1 3 1 2 2 2 1 1
10
4 3 5 4 5 4 1 4 3 4
8
1 2 1 3 2 3 ...

output:

3

result: