QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743710 | #6794. Sequence to Sequence | Arghariza | WA | 125ms | 8656kb | C++14 | 1.8kb | 2024-11-13 19:51:56 | 2024-11-13 19:51:58 |
Judging History
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;
}
}
F (i, 0, n) {
memset(f[i], -0x3f, sizeof(f[i]));
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5980kb
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
Wrong Answer
time: 125ms
memory: 8656kb
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:
wrong answer 19126th words differ - expected: '17', found: '15'