QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133522 | #4936. Shopping Changes | SolitaryDream# | WA | 0ms | 5804kb | C++20 | 1.9kb | 2023-08-02 10:37:08 | 2023-08-02 10:37:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 1010;
const int M = 21010;
int n, a[N], b[N], sa[N];
pii f[M][N], g[M][N];
inline void U(pii &u, pii v) {
if (u == pii(0, 0)) u = v;
else u = min(u, v);
}
inline pii Process(int *a, pii u) {
if (u.second < a[u.first]) return u;
return pii(u.first + 1, 0);
}
inline void Update(int i, int ax, int ay, int bx, int by) {
if (ax == bx) {
if (ay == 0) if (i + b[bx] - by < M) U(g[i + b[bx] - by][bx], pii(ax, ay));
if (by == 0) if (i + a[ax] - ay < M) U(f[i + a[ax] - ay][ax], pii(bx, by));
} else {
int a_rm = a[ax] - ay, b_rm = b[bx] - by;
if (ax == n + 1) {
if (i + b_rm < M) U(g[i + b_rm][bx], pii(ax, ay));
} else {
if (a_rm <= b_rm) if (i + a_rm < M) U(f[i + a_rm][ax], Process(b, pii(bx, by + a_rm)));
if (b_rm <= a_rm) if (i + b_rm < M) U(g[i + b_rm][bx], Process(a, pii(ax, ay + a_rm)));
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
for (int i = 1; i <= n; ++i) scanf("%d", b + i);
for (int i = n; i; --i) sa[i] = sa[i + 1] + a[i];
f[a[1]][1] = pii(1, 0);
g[b[1]][1] = pii(1, 0);
int ans = 1e9;
for (int i = 0; i < M; ++i)
for (int j = 1; j <= n; ++j) {
if (f[i][j] != pii(0, 0)) {
auto [x, y] = f[i][j];
Update(i, j + 1, 0, x, y);
}
if (g[i][j] != pii(0, 0)) {
auto [x, y] = g[i][j];
if (j == n) {
printf("Update %d %d %d\n", i, x, y);
ans = min(ans, i + sa[x] - y);
}
if (j + 1 <= n) Update(i, x, y, j + 1, 0);
if (j + 2 <= n) Update(i, x, y, j + 2, 0);
}
}
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5804kb
input:
3 3 5 6 7 6 2 3 4 8 9 10 2 100 99 3 5 6 7
output:
Update 9 2 0 Update 12 4 0 Update 15 3 0 Update 18 4 0 12
result:
wrong answer 1st lines differ - expected: '0', found: 'Update 9 2 0'