QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322820#6769. Monster HunterYaremaAC ✓14ms4340kbC++142.6kb2024-02-07 19:56:442024-02-07 19:56:45

Judging History

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

  • [2024-02-07 19:56:45]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:4340kb
  • [2024-02-07 19:56:44]
  • 提交

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';
}
void print(vector<int> a, string s)
{
	cerr << s << '\n';
	for (auto k : a)
		cerr << k << ' ';
	cerr << '\n';
}

bool can(VI h, vector<LL>& cnt)
{
	//print(cnt, "CNT");
	//print(h, "H");
	int m = SZ(h);
	FOR (i, 0, m)
	{
		if (h[i] >= 3 && h[i] & 1 && cnt[2] > 0)
		{
			h[i] -= 3;
			cnt[2]--;
		}
	}
	//print(cnt, "CNT");
	//print(h, "H");
	FOR (i, 0, m)
	{
		if (h[i] & 1 && cnt[0])
		{
			h[i]--;
			cnt[0]--;
		}
	}
	//print(cnt, "CNT");
	//print(h, "H");
	FOR (i, 0, m)
	{
		LL need = h[i] / 6;
		int x = min(need, cnt[2] / 2);
		h[i] -= x * 6;
		cnt[2] -= x * 2;
	}
	//print(cnt, "CNT");
	//print(h, "H");
	if (cnt[2] == 1)
	{
		FOR (i, 0, m)
		{
			if (h[i] >= 3)
			{
				h[i] -= 3;
				cnt[2]--;
				if (cnt[0])
				{
					h[i]--;
					cnt[0]--;
				}
				break;
			}
		}
	}
	FOR (i, 0, m)
	{
		if (h[i] >= 3 && cnt[2])
		{
			h[i] -= 3;
			cnt[2]--;
		}
	}
	FOR (i, 0, m)
	{
		if (h[i] & 1 && cnt[0])
		{
			h[i]--;
			cnt[0]--;
		}
	}
	//print(cnt, "CNT");
	//print(h, "H");
	cnt[1] += cnt[2];
	cnt[1] += cnt[0] / 2;
	LL y = 0;
	FOR (i, 0, m)
		y += (h[i] + 1) / 2;
	return y <= cnt[1];
}

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;
	//LL l = 5, r = 7;
	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;
}



这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 1ms
memory: 3580kb

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
15
3
7
19
12
3
8
7
20
5
10
6
10
3
10
16
1
5
6
10
14
13
8
8
5
13
15
5
10
16
14
10
1
10
4
3
16
5
4
7
8
7
5
13
10
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:

ok 100 lines

Test #3:

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

input:

100
22
3 3 3 1 3 2 3 3 3 3 2 2 3 3 1 2 1 2 3 2 3 1
3
10 1 8
11
1 3 2 1 3 3 1 1 1 1 1
3
3 5 13
21
3 1 2 3 2 1 2 1 3 2 2 1 1 1 1 3 2 3 2 3 2
4
1 5 7 10
8
2 1 3 3 2 2 2 2
3
8 11 8
4
2 1 1 2
2
12 8
26
1 2 3 3 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 1 1 3 2 3 3 2
4
8 6 5 13
30
1 1 3 2 2 1 2 3 1 3 3 2 3 2 2 3 1 2 3...

output:

8
13
12
13
13
17
11
7
6
23
5
5
12
20
2
22
9
10
3
4
22
12
10
5
9
5
11
17
1
20
9
26
8
13
14
10
13
9
17
5
6
11
17
17
18
16
5
19
8
2
13
20
9
8
19
14
16
12
20
19
8
24
7
16
8
5
4
21
1
4
8
9
10
15
7
11
10
2
6
3
4
18
26
8
9
8
11
3
8
6
9
7
20
2
10
22
16
20
14
13

result:

ok 100 lines

Test #4:

score: 0
Accepted
time: 14ms
memory: 3620kb

input:

100
773
2 3 3 2 1 1 1 3 1 3 2 3 2 2 2 2 1 3 3 3 2 3 3 2 2 3 2 1 1 1 3 2 1 1 2 1 2 3 3 3 1 1 3 2 1 3 1 2 3 1 1 1 3 3 1 2 1 3 2 2 3 3 2 3 3 1 3 1 2 3 3 3 2 3 2 1 3 2 3 3 2 2 2 2 3 2 3 1 2 3 2 1 1 1 1 2 2 3 1 2 1 2 2 1 2 3 3 2 2 3 1 3 2 1 2 1 3 3 2 2 3 3 3 1 2 2 3 1 1 3 1 3 3 3 1 3 3 1 1 2 3 2 3 2 2 3 ...

output:

141465623985
146640177725
193302027436
185725363449
27377351959
26962096046
122965020242
164575549427
134405124981
142123242931
239651450114
203676837595
215746363813
176133012841
126667756527
14661286739
153111144139
53633915881
14813690750
194934023573
28317268803
133277272607
239614512471
1786238...

result:

ok 100 lines

Test #5:

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

input:

1
45105
3 1 2 1 1 1 1 2 1 3 3 2 1 1 1 3 3 2 2 1 2 1 2 1 3 1 1 3 3 1 3 1 3 3 2 2 1 1 1 1 1 2 2 2 3 3 1 3 2 1 2 2 1 1 2 2 2 3 1 1 3 1 3 3 3 3 2 2 1 3 3 2 1 1 1 1 2 3 1 1 3 1 1 2 2 1 1 2 2 1 3 2 2 3 2 1 3 2 3 3 2 3 2 2 3 2 1 3 1 1 1 3 2 1 1 3 2 2 3 3 1 3 3 3 2 1 3 1 3 3 3 1 3 2 3 2 3 3 3 2 1 1 1 2 1 3 ...

output:

52702719862

result:

ok single line: '52702719862'

Test #6:

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

input:

1
58785
3 2 2 2 2 2 1 1 1 2 1 2 1 1 3 2 1 2 1 2 2 1 1 3 1 3 2 2 2 2 2 2 2 1 1 2 2 3 3 3 2 1 2 3 3 1 3 3 2 1 1 3 3 3 2 1 3 3 1 2 2 1 1 1 2 3 3 1 3 2 1 1 2 2 3 3 1 1 2 2 2 2 1 3 2 2 3 2 3 2 2 3 2 3 1 1 1 1 2 3 1 1 2 2 3 3 3 2 1 1 1 3 1 2 1 1 1 3 2 2 3 1 2 2 3 2 2 2 1 3 3 1 1 3 1 3 3 1 1 3 3 2 1 2 2 1 ...

output:

203100926

result:

ok single line: '203100926'

Test #7:

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

input:

10
9
3 3 3 1 1 3 2 1 2
5
6 10 4 3 3
8
3 2 2 2 1 3 3 1
3
7 6 1
6
1 3 2 1 2 3
5
1 9 3 6 3
8
2 1 3 1 3 1 2 3
4
10 4 4 10
3
3 3 1
3
4 4 3
6
3 2 3 3 3 1
1
6
7
3 2 1 1 1 3 1
5
7 4 4 8 7
3
2 2 3
5
5 1 6 8 6
1
3
3
9 10 1
10
3 3 3 1 3 3 3 3 3 1
1
6

output:

12
7
12
15
5
3
17
12
8
2

result:

ok 10 lines