QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#186846 | #6794. Sequence to Sequence | zhoukangyang | AC ✓ | 115ms | 6068kb | C++11 | 1.4kb | 2023-09-24 12:31:01 | 2023-09-24 12:31:01 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define ll long long
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a))
using namespace std;
const int N = 1 << 20;
int n;
int a[N], b[N];
ll dp[1 << 2], ndp[1 << 2];
void Main() {
cin >> n;
L(i, 1, n) {
cin >> a[i];
}
L(i, 1, n) {
cin >> b[i];
}
me(dp, -0x3f);
dp[0] = 0;
L(i, 1, n) {
if(!a[i]) {
if(b[i]) {
cout << "-1\n";
return ;
}
continue;
}
me(ndp, -0x3f);
L(s, -1, 1) {
if(b[i] == 0 && s != 0) continue;
L(w, s - 1, s + 1) if((b[i] > 0 && w <= 0) || (!b[i] && w >= 0)) {
ll add = (b[i] - a[i]) * s;
if(b[i] == 0) add += a[i] * w;
else add += (a[i] - 1) * w;
int v[2] = {w - s, s};
L(S, 0, (1 << 2) - 1) {
int ok = 1, go = 0;
L(j, 0, 1) {
int SUM = max((S >> j & 1) + v[j], 0);
if(SUM > 1) {
ok = 0;
} else if(SUM) {
go |= 1 << j;
}
}
if(ok) {
ndp[go] = max(ndp[go], dp[S] + add);
}
}
}
}
swap(dp, ndp);
}
cout << *max_element(dp, dp + 4) << '\n';
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t; while(t--) Main();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5680kb
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: 0
Accepted
time: 115ms
memory: 6068kb
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:
ok 110121 tokens
Extra Test:
score: 0
Extra Test Passed