ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#321 | #7. 「WyOJ Round 1」归 · 星穗垂野 | cxm1024 | 10 | 2180ms | 30728kb | C++23 | 1.6kb | 2025-04-18 17:48:07 | 2025-04-18 18:06:28 |
answer
#include <bits/stdc++.h>
#define deb cout << "in " << __LINE__ << "\t: "
using namespace std;
#define int long long
int n, C, a[100010], b[100010], s[100010], t[20][100010], lst[100010];
#define lg(x) (31 ^ __builtin_clz(x))
int query(int l, int r) {
int len = lg(r - l + 1);
return __gcd(t[len][l], t[len][r - (1 << len) + 1]);
}
vector<pair<int, int>> p[100010];
int tr[100010], dp[100010];
void add(int x, int y) {
for (; x <= n; x += x & -x)
tr[x] = min(tr[x], y);
}
int getmn(int x, int res = 1e18) {
x = min(x, n);
for (; x; x -= x & -x)
res = min(res, tr[x]);
return res;
}
void Solve(int test) {
cin >> n >> C;
for (int i = 1; i <= n; i++)
cin >> a[i], t[0][i] = a[i], tr[i] = 1e18, dp[i] = 1e18, p[i].clear();
for (int i = 1; i <= n; i++)
cin >> b[i], s[i] = s[i - 1] + b[i];
for (int i = 0; i < 18; i++)
for (int j = 1; j + (2 << i) - 1 <= n; j++)
t[i + 1][j] = __gcd(t[i][j], t[i][j + (1 << i)]);
for (int i = 1; i <= n; i++) {
int l = 0, r = i;
while (l < r) {
int mid = (l + r + 1) / 2;
if (query(mid, i) <= i - mid + 1)
l = mid;
else r = mid - 1;
}
lst[i] = l;
if (l) p[l].push_back({i, query(l, i)});
}
add(1, 0);
for (int i = 1; i <= n; i++) {
for (auto [r, x] : p[i])
dp[r] = getmn(x) + C + (s[r] - s[i - 1]) * x;
if (lst[i]) add(i, dp[i]);
}
int res = 1e18;
for (int i = 1; i <= n; i++)
res = min(res, dp[i]);
cout << res << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
for (int i = 1; i <= T; i++) Solve(i);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 7628kb
input:
1000 10 -759451753 8 10 5 7 5 10 6 10 2 1 5 6 5 4 9 8 5 4 1 3 10 -953033990 4 10 10 8 8 2 1 7 4 1 0 ...
output:
-1518903474 -1906067956 -14232726 -601693580 -645321017 -851981042 -432437219 -849983494 -995876464 ...
result:
wrong answer 1st numbers differ - expected: '-2278355214', found: '-1518903474'
Test #2:
score: 10
Accepted
time: 248ms
memory: 26528kb
input:
5 94253 6998801 88374 94432 21568 79110 3746 94223 86214 12083 54743 1622 16110 18595 18994 3665 547...
output:
6999125 764376403 718240695 1381649585 885156744
result:
ok 5 number(s): "6999125 764376403 718240695 1381649585 885156744"
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 11640kb
input:
5 120 -848255662 53358 95098 92852 36846 80052 83050 44071 22632 50005 52339 7339 38495 66618 6337 5...
output:
-1696097966 -263423849 -385508249 -1644392346 -970613048
result:
wrong answer 1st numbers differ - expected: '-11025209476', found: '-1696097966'
Test #4:
score: 0
Wrong Answer
time: 5ms
memory: 11740kb
input:
5 100 -964452256 94167 36596 60051 82090 55625 56197 94589 29844 14929 68497 81714 90264 66283 96767...
output:
-1928674938 -1957172012 -85302292 -706386022 -975286882
result:
wrong answer 1st numbers differ - expected: '-7714370390', found: '-1928674938'
Test #5:
score: 0
Wrong Answer
time: 9ms
memory: 15788kb
input:
5 984 -715414516 65632 15191 55392 53178 88695 20308 44882 16528 12986 81169 76880 2239 81264 13866 ...
output:
-1430739657 -1655397059 -700730085 -994178012 -324962126
result:
wrong answer 1st numbers differ - expected: '-72952473687', found: '-1430739657'
Test #6:
score: 0
Wrong Answer
time: 371ms
memory: 30728kb
input:
5 83593 -175988991 46605 26358 5204 30137 41225 11710 75224 14130 56433 62524 29873 59483 22318 2619...
output:
-351711967 -887488006 -1028097824 -564564549 -1096907190
result:
wrong answer 1st numbers differ - expected: '-1656361289384', found: '-351711967'
Test #7:
score: 0
Wrong Answer
time: 405ms
memory: 29680kb
input:
5 96302 -451340376 2672 47391 49737 61648 38099 10679 28316 91168 97182 40556 20560 89630 45931 9187...
output:
-902619801 -1385996674 -261498007 97842263 -2164267547
result:
wrong answer 1st numbers differ - expected: '-4877361987440', found: '-902619801'
Test #8:
score: 0
Wrong Answer
time: 382ms
memory: 30712kb
input:
5 82075 -915749780 41503 94470 21657 60519 10090 65640 80911 29436 63096 68715 79609 87499 26240 606...
output:
-1831479043 -533532758 -803472133 -776237997 -1877329517
result:
wrong answer 1st numbers differ - expected: '-8500967499879', found: '-1831479043'
Test #9:
score: 0
Wrong Answer
time: 364ms
memory: 28744kb
input:
5 86206 -158351237 12910 53574 97622 75378 61116 40492 87106 60678 72614 2146 43673 15147 23123 7469...
output:
-474365433 -848614166 -3202809425 -1243917208 -1789236059
result:
wrong answer 1st numbers differ - expected: '-1508037508585', found: '-474365433'
Test #10:
score: 0
Wrong Answer
time: 384ms
memory: 29368kb
input:
5 87683 -236086252 88768 76878 54808 98282 70961 83599 48353 34381 40413 95288 24241 74500 52966 994...
output:
-707512474 -1953984643 -1651187059 -1185348004 -1192080812
result:
wrong answer 1st numbers differ - expected: '-2319782085288', found: '-707512474'