QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743706#6794. Sequence to SequenceArgharizaTL 1ms7476kbC++141.8kb2024-11-13 19:51:072024-11-13 19:51:10

Judging History

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

  • [2024-11-13 19:51:10]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7476kb
  • [2024-11-13 19:51:07]
  • 提交

answer

#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define R(i, x, y) for (int i = (x); i >= (y); i--)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
#define int long long

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
bool Mbe;

const int N = 1e5 + 5;
const int inf = 0x3f3f3f3f3f3f3f3f;

int n;
int a[N], b[N];
int f[N][2][2];

void solve() {
	cin >> n;
	F (i, 1, n) {
		cin >> a[i];
	}
	F (i, 1, n) {
		cin >> b[i];
	}
	F (i, 1, n) {
		if (!a[i] && b[i]) {
			cout << -1 << '\n';
			return;
		}
	}
	memset(f, -0x3f, sizeof(f));
	f[0][0][0] = 0;
	F (i, 1, n) {
		if (!b[i]) {
			F (x, 0, 1) {
				F (y, 0, 1) {
					if (f[i - 1][x][y] == -inf) {
						continue;
					}
					F (u, 0, 1) {
						int _y = max({ 0ll, y + u, u });
						if (_y > 1) {
							continue;
						}
						f[i][x][_y] = max(f[i][x][_y], f[i - 1][x][y] + a[i] * u);
					}
				}
			}
		} else {
			F (x, 0, 1) {
				F (y, 0, 1) {
					if (f[i - 1][x][y] == -inf) {
						continue;
					}
					F (v, 0, 1) {
						F (w, -1, 1) {
							int _x = max({ 0ll, x + w, w });
							int _y = max({ 0ll, y - w - v, - w - v });
							if (_x > 1 || _y > 1) {
								continue;
							}
							f[i][_x][_y] = max(f[i][_x][_y], f[i - 1][x][y] + (1 - a[i]) * v + (b[i] - a[i]) * w);
						}
					}
				}
			}
		}
	}
	cout << max({ f[n][0][0], f[n][0][1], f[n][1][0], f[n][1][1] }) << '\n';
}

bool Med;
signed main() {
	// FIO("");
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
	int T = 1;
	cin >> T;
	while (T--) solve();
	cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
	return 0;
}

詳細信息

Test #1:

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

input:

2
5
1 1 1 1 1
2 0 2 0 2
7
3 1 2 3 2 1 4
2 0 0 0 0 0 2

output:

3
3

result:

ok 2 tokens

Test #2:

score: -100
Time Limit Exceeded

input:

110121
5
0 0 0 0 0
1 4 5 4 1
5
1 0 0 0 0
0 6 8 6 1
5
2 0 0 0 0
4 4 1 3 6
5
3 0 0 0 0
5 1 1 7 6
5
4 0 0 0 0
6 8 7 0 8
5
5 0 0 0 0
5 9 7 7 5
5
6 0 0 0 0
9 2 2 8 0
5
7 0 0 0 0
9 4 7 0 9
5
8 0 0 0 0
6 7 3 7 5
5
9 0 0 0 0
4 0 9 1 4
5
0 1 0 0 0
0 6 6 3 0
5
1 1 0 0 0
3 4 3 4 9
5
2 1 0 0 0
0 4 0 1 4
5
3 1 0...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result: