QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322345#6769. Monster HunterPetroTarnavskyi#WA 1ms3840kbC++201.8kb2024-02-06 21:35:142024-02-06 21:35:15

Judging History

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

  • [2024-02-06 21:35:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3840kb
  • [2024-02-06 21:35:14]
  • 提交

answer

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); 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;


bool check(LL cnt1, LL cnt2, LL cnt3, VI hp)
{
	FOR(i, 0, SZ(hp))
	{
		if(hp[i] % 2 == 1 && hp[i] >= 3 && cnt3 > 0)
		{
			hp[i] -= 3;
			cnt3--;
		}
	}
	FOR(i, 0, SZ(hp))
	{
		LL num = min((LL)hp[i] / 6, cnt3 / 2);
		hp[i] -= 6 * num;
		cnt3 -= 2 * num;
	}
	FOR(i, 0, SZ(hp))
	{
		if(hp[i] == 4 && cnt3 > 0)
		{
			hp[i] -= 3;
			cnt3--;
		}
	}
	cnt2 += cnt3;
	FOR(i, 0, SZ(hp))
	{
		if(hp[i] % 2 == 1 && cnt1 > 0)
		{
			hp[i] -= 1;
			cnt1--;
		}
	}
	cnt2 += (cnt1 / 2);
	FOR(i, 0, SZ(hp))
	{
		LL num = (hp[i] + 1) / 2;
		cnt2 -= num;
	}
	return cnt2 >= 0;	
}

void solve()
{
	int n;
	cin >> n;
	VI cnt[4];
	FOR(i, 0, 4)
		cnt[i].resize(n + 1);
	FOR(i, 0, n)
	{
		int x;
		cin >> x;
		FOR(j, 0, 4)
			cnt[j][i + 1] = cnt[j][i];
		cnt[x][i + 1]++;
	}
	int m;
	cin >> m;
	VI hp(m);
	FOR(i, 0, m)
		cin >> hp[i];
	
	LL L = 0, R = 1e17;
	while(R - L > 1)
	{
		LL M = (L + R) / 2;
		LL full = M / n;
		LL ost = M % n;
		
		LL cnt1 = cnt[1][n] * full + cnt[1][ost];
		LL cnt2 = cnt[2][n] * full + cnt[2][ost];
		LL cnt3 = cnt[3][n] * full + cnt[3][ost];
		
		if(check(cnt1, cnt2, cnt3, hp))
			R = M;
		else
			L = M;
	}
	cout << R << "\n";
}


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

詳細信息

Test #1:

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

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

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

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

result:

wrong answer 21st lines differ - expected: '22', found: '23'