QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322420#6769. Monster HunterYarema#WA 1ms3656kbC++143.0kb2024-02-07 00:02:312024-02-07 00:02:32

Judging History

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

  • [2024-02-07 00:02:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3656kb
  • [2024-02-07 00:02:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int MAGIC = 5;

void print(vector<LL> a, string s)
{
	cerr << s << '\n';
	for (auto k : a)
		cerr << k << ' ';
	cerr << '\n';
}

bool can(VI& h, vector<LL>& cnt)
{
	//print(cnt, "CNT");
	int m = SZ(h);
	vector<LL> a(m);
	FOR (i, 0, m)
	{
		if (h[i] <= MAGIC + 2)
			a[i] = h[i];
		else
		{
			LL c = (h[i] - MAGIC) / 3;
			a[i] = h[i] - c * 3;
			LL x = min(c, cnt[2]);
			cnt[2] -= x;
			c -= x;
			cnt[0] -= c;
			cnt[1] -= c;
		}
	}
	//print(a, "A");
	if (*min_element(ALL(cnt)) < 0 || *max_element(ALL(a)) > MAGIC + 2)
		return false;
	FOR (i, 0, m)
	{
		if (cnt[2] == 0)
			break;
		if (a[i] < 3)
			continue;
		if (a[i] & 1)
		{
			a[i] -= 3;
			cnt[2]--;
		}
	}
	FOR (i, 0, m)
	{
		if (a[i] & 1 && cnt[0])
		{
			a[i]--;
			cnt[0]--;
		}
	}
	//print(cnt, "CNT");
	//print(a, "A");
	if (cnt[0] == 0 && cnt[2] == 0)
	{
		LL y = 0;
		FOR (i, 0, m)
		{
			y += (a[i] + 1) / 2;
		}
		return cnt[1] >= y;
	}
	vector<LL> c(MAGIC + 4);
	FOR (i, 0, m)
		c[a[i]]++;
	int j = 0;
	//print(c, "C");
	while (c[1] > 0 && j < 3)
	{
		LL x = min((LL)c[1], cnt[j]);
		cnt[j] -= x;
		c[1] -= x;
		j++;
	}
	
	//print(c, "C");
	if (c[1] > 0)
		return false;
	
	LL four = min(cnt[0], cnt[2]);
	cnt[0] -= four;
	cnt[2] -= four;
	
	cnt[1] += cnt[2];
	cnt[1] += cnt[0] / 2;
	
	LL x = min(four, c[4]);
	c[4] -= x;
	four -= x;
	
	x = min(four, c[6]);
	c[6] -= x;
	four -= x;
	c[2] += x;
	cnt[1] += four;
	
	x = min(c[4], cnt[1] / 2);
	c[4] -= x;
	cnt[1] -= x * 2;
	
	x = min(c[6], cnt[1] / 3);
	c[6] -= x;
	cnt[1] -= x * 3;
	
	x = min(c[2], cnt[1]);
	c[2] -= x;
	cnt[1] -= x;
	
	//print(c, "c");
	
	c[0] = 0;
	return *max_element(ALL(c)) == 0;
}

void solve()
{
	int n;
	cin >> n;
	VI a(n);
	VI c(3, 0);
	vector<VI> cnt(3, VI(n + 1));
	FOR (i, 0, n)
	{
		cin >> a[i];
		a[i]--;
		c[a[i]]++;
		cnt[a[i]][i + 1]++;
	}
	FOR (i, 0, 3)
		FOR (j, 1, n + 1)
			cnt[i][j] += cnt[i][j - 1];
	int m;
	cin >> m;
	VI v(m);
	FOR (i, 0, m)
		cin >> v[i];
	LL sum = accumulate(ALL(v), 0ll);
	LL l = 0, r = 1e15;
	while (l + 1 < r)
	{
		LL mid = (l + r) / 2;
		vector<LL> cn(3);
		LL all = mid / n;
		FOR (i, 0, 3)
			cn[i] = c[i] * all + cnt[i][mid % n];
		LL s2 = cn[0] + cn[1] * 2 + cn[2] * 3;
		if (s2 < sum)
		{
			l = mid;
			continue;
		}
		
		//cerr << mid << ":\n";
		
		if (can(v, cn))
			r = mid;
		else
			l = mid;
	}
	cout << r << '\n';
	//cerr << db(clock()) / CLOCKS_PER_SEC << '\n';
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
17
3
7
19
12
3
8
7
20
5
10
6
11
3
10
16
1
5
6
10
14
13
8
9
5
13
15
5
10
16
15
10
1
10
4
3
16
5
4
7
8
7
5
13
11
10
10
14
3
9
8
19
16
8
25
11
21
2
3
14
12
4
12
17
22
11
3
14
15
2
9
12
7
3
9
4
9
11
2
2
5
5
3
2
2
4
6
7
10
3
14
2
1
5
4
8
13
14
16

result:

wrong answer 2nd lines differ - expected: '15', found: '17'