QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#660204#6769. Monster HuntermengxinzclWA 1ms5728kbC++232.9kb2024-10-20 09:02:512024-10-20 09:02:51

Judging History

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

  • [2024-10-20 09:02:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5728kb
  • [2024-10-20 09:02:51]
  • 提交

answer

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

const int N = 1e5 + 5;
int ar[N], br[N];
int pre[4][N];
int a, b, c;

void solve() {
	int n, m;
	cin >> n;
	a = c = b = 0;

	for (int i = 1; i <= n; ++i)
		cin >> ar[i];

	cin >> m;
	for (int i = 1; i <= m; ++i)
		cin >> br[i];

	for (int i = 1; i <= n; ++i) {
		pre[1][i] = pre[1][i - 1];
		pre[2][i] = pre[2][i - 1];
		pre[3][i] = pre[3][i - 1];
		pre[ar[i]][i] = pre[ar[i]][i - 1] + 1;
	}
	for (int i = 1; i <= m; ++i) {
		if (br[i] % 3 == 1) {
			c += 1;
		}
		if (br[i] % 3 == 2) {
			b += 1;
		}
		a += br[i] / 3;
	}
	auto check = [&](int mid) -> bool {
		int x, y, z;
		x = mid / n * pre[3][n] + pre[3][mid % n];
		y = mid / n * pre[2][n] + pre[2][mid % n];
		z = mid / n * pre[1][n] + pre[1][mid % n];
		int er = 0, yi = 0;
		for (int i = 1; i <= m; ++i) {
			int t = br[i] / 3;
			int ee = br[i] % 3;
			if (x > t) {
				x -= t;
				t = 0;
			} else if (x > 0) {
				t -= x;
				x = 0;
			}
			if (t > 0) {
				if (y > 0 and z > 0) {
					if (min(y, z) > t) {
						y -= t;
						z -= t;
						t = 0;
					} else {
						int mu = min(y, z);
						t -= mu;
						y -= mu;
						z -= mu;
					}
				}
				if (y > 0 and t > 0) {
					if ((3 * t) % 2 == 0) {
						int mu = y;

						y -= (t * 3) / 2;
						t -= (mu * 2) / 3;
					} else {
						y -= (((t * 3) / 2) + 1);
						t -= ((((t * 3) / 2) + 1) * 2) / 3;
					}
				}
				if (z > 0 and t > 0) {
					int sss = z;
					if (z >= t * 3) {
						z -= t * 3;
						t = 0;
					} else {
						t -= z / 3;
						z = z % 3;
					}
				}
			}
			if (ee == 1) {
				yi += 1;
			}
			if (ee == 2) {
				er += 1;
			}
			if (t > 0) {
				return false;
			}
		}
//		cout << yi << " " << er << " " << x << ' ' << y << ' ' << z << " " << mid << endl;
		if (yi > 0) {
			if (z > yi) {
				z -= yi;
				yi = 0;
			} else if (z > 0) {
				yi -= z;
				z = 0;
			}
			if (y > yi) {
				y -= yi;
				yi = 0;
			} else if (y > 0) {
				yi -= y;
				y = 0;
			}
			if (x > yi) {
				x -= yi;
				yi = 0;
			} else if (x > 0) {
				yi -= x;
				x = 0;
			}
		}
		if (er > 0) {
			if (y > er) {
				y -= er;
				er = 0;
			} else if (y > 0) {
				er -= y;
				y = 0;
			}
			if (z / 2 > er) {
				z -= er * 2;
				er = 0;
			} else if (z / 2 > 0) {
				er -= z / 2;
				z = z % 2;
			}
			if (x > er) {
				x -= er;
				er = 0;
			} else if (x > 0) {
				er -= x;
				x = 0;
			}
		}
		if (er > 0 or yi > 0) {
			return false;
		}
		if (x < 0 or y < 0 or z < 0) {
			return false;
		}
		return true;


	};

	int l = 1, r = 1e9;
	while (l < r) {
		int mid = l + r >> 1;
		if (check(mid))
			r = mid;
		else
			l = mid + 1;
	};
	cout << r << '\n';
}

signed main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	cin >> n;
	while (n--)
		solve();
	return 0;
}

详细

Test #1:

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

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

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
20
12
3
8
7
20
5
10
6
10
3
10
18
1
5
6
10
14
13
8
8
5
13
15
5
10
16
14
10
1
12
4
3
16
5
4
7
8
7
5
13
10
10
10
14
3
9
9
19
18
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 5th lines differ - expected: '19', found: '20'