ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197904 | #2399. 全连 | Womind | 100 | 1750ms | 79392kb | C++ | 2.2kb | 2023-11-16 11:47:56 | 2023-11-16 12:09:08 |
answer
/*
Name:
Copyright:
Author: 不要和 std 命名空间冲突!
Date: 11/16/2023 11:03:56 AM
Description:等会造成误差!文件读写即可!
*/
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repe(i,a,b) for (int i = (a); i >= (b); i--)
bool Mbe;
inline int read() {
int ans = 0, f = 1; char ch = getchar();
for(; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -f;
for(; ch >= '0' && ch <= '9'; ch = getchar()) ans = (ans << 3) + (ans << 1) + ch - '0';
return ans * f;
}
const int mod = 1e9 + 7;
int ksm(int truth, int power) {
int ans = 1;
while(power) {
if(power & 1) ans = 1ll * ans * truth % mod;
power >>= 1;
truth = 1ll * truth * truth % mod;
}
return ans;
}
const int Z = 1e6 + 5;
int fac[Z], ifac[Z];
void init_fac(int x) {
for(int i = fac[0] = 1; i <= x; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
ifac[x] = ksm(fac[x], mod - 2);
for(int i = x - 1; i >= 0; i--) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;
}
const int N = 1e6 + 1;
int a[N], b[N], n, t, m, maxx = 0;
bool vis[N];
long long dp[N];
long long tr[N << 1];
void update(int x, long long val){
while(x <= maxx) {
tr[x] = max(tr[x], val);
x += x & (-x);
}
}
long long query(int x) {
long long ans = 0;
while(x) {
ans = max(ans, tr[x]);
x -= x & (-x);
}
return ans;
}
vector<int> num[N];
void mian() {
n = read();
rep(i,1,n) {
a[i] = read(), maxx = max(a[i] + i, maxx);
if(i + a[i] <= n)
num[i + a[i]].push_back(i);
}
rep(i,1,n) b[i] = read();
long long ans = 0;
rep(i,1,n) { // 决策优化?
int c = num[i].size() - 1;
for(int j = 0; j <= c; j++) update(num[i][j], dp[num[i][j]]);
// rep(j,0,num[i].size() - 1) cout << num[i].size() << endl; //
dp[i] = query(max(0, i - a[i])) + 1ll * b[i] * a[i];
ans = max(dp[i], ans);
}
// ans = query(n); 有的没插入
cout << ans << endl;
}
bool Med;
int main(){
// freopen("A.txt", "r", stdin);
// freopen(".out", "w", stdout);
fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0);
int T = 1;
while(T--) mian();
cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 24744kb
input:
5 5 3 5 5 1 480208416 560202151 230193932 182093570 999846296
output:
2680452749
result:
ok single line: '2680452749'
Test #2:
score: 5
Accepted
time: 4ms
memory: 24760kb
input:
10 3 2 9 3 4 1 4 7 1 8 32905395 72720216 54089340 289875333 847413895 598817637 206111130 144722879 ...
output:
4191763507
result:
ok single line: '4191763507'
Test #3:
score: 5
Accepted
time: 3ms
memory: 24756kb
input:
15 9 2 13 7 2 4 10 4 2 3 3 1 2 2 2 860947809 695835339 13996045 709112244 119816376 441006970 575090...
output:
10490468135
result:
ok single line: '10490468135'
Test #4:
score: 5
Accepted
time: 4ms
memory: 24752kb
input:
20 2 10 15 4 7 1 2 2 7 3 17 6 4 4 5 4 4 4 2 1 457301510 838843149 408120703 43551970 387080784 10169...
output:
11883246598
result:
ok single line: '11883246598'
Test #5:
score: 5
Accepted
time: 0ms
memory: 24800kb
input:
1000 103 2 2 13 4 5 183 175 29 1 675 1 199 195 1 8 7 19 1 945 4 6 574 8 1 13 2 16 2 40 175 33 2 3 35...
output:
1162897804752
result:
ok single line: '1162897804752'
Test #6:
score: 5
Accepted
time: 10ms
memory: 24840kb
input:
2000 1252 2 2 3 189 1847 22 114 7 48 15 157 1160 1419 10 31 76 114 2 369 2 5 1 460 63 1 8 1130 63 17...
output:
2771903520915
result:
ok single line: '2771903520915'
Test #7:
score: 5
Accepted
time: 3ms
memory: 24976kb
input:
5000 4842 6 3352 7 318 163 170 1 4325 378 15 2 1289 1 2 7 946 12 1945 1 9 9 255 4 4543 8 3006 28 2 3...
output:
7861941062084
result:
ok single line: '7861941062084'
Test #8:
score: 5
Accepted
time: 0ms
memory: 25180kb
input:
10000 87 8310 1 21 9174 12 1524 1 1 457 1 1380 9929 121 2 3846 4 4 41 6282 9 8 445 807 362 32 8986 8...
output:
17334962387424
result:
ok single line: '17334962387424'
Test #9:
score: 5
Accepted
time: 10ms
memory: 26028kb
input:
30000 79 110 19001 3892 137 20285 2 104 167 12458 29 12 1 7544 35 18127 147 21 2712 29763 868 24597 ...
output:
51316652640940
result:
ok single line: '51316652640940'
Test #10:
score: 5
Accepted
time: 15ms
memory: 26876kb
input:
50000 1547 1187 141 27 15818 12251 7271 29 2 8 13 2 3818 398 8167 17161 14 16962 6760 540 8784 7 240...
output:
88026787637620
result:
ok single line: '88026787637620'
Test #11:
score: 5
Accepted
time: 31ms
memory: 28976kb
input:
100000 9736 5862 1 2099 11612 21 24021 14624 446 396 81 2 1899 49526 781 69432 7 10177 1320 124 471 ...
output:
180410914037070
result:
ok single line: '180410914037070'
Test #12:
score: 5
Accepted
time: 66ms
memory: 33196kb
input:
200000 1412 5 2 13253 1 1 1 185647 47 1 507 150635 376 7 74 47462 53 4 5411 3 5154 130 19 265 8 185 ...
output:
376348758470573
result:
ok single line: '376348758470573'
Test #13:
score: 5
Accepted
time: 159ms
memory: 45944kb
input:
500000 383 119 2 1429 1026 29 301750 117 28940 26 375666 2347 249 62156 74903 8 22 2670 430211 140 3...
output:
959624672322043
result:
ok single line: '959624672322043'
Test #14:
score: 5
Accepted
time: 261ms
memory: 58544kb
input:
800000 886 1 403044 156168 25247 19 6686 1935 1483 338 2 7 26 6 84 62996 2 1 4 21109 41190 9828 7294...
output:
1542878834606328
result:
ok single line: '1542878834606328'
Test #15:
score: 5
Accepted
time: 336ms
memory: 67132kb
input:
1000000 237 426 2208 4 36156 454152 1 48361 76425 46521 3 684890 41403 32 274 7077 53 20 6 4 191644 ...
output:
1908394076801355
result:
ok single line: '1908394076801355'
Test #16:
score: 5
Accepted
time: 342ms
memory: 67128kb
input:
1000000 60 188620 109 225192 99984 137997 442 75 6451 26437 72089 45937 92 2011 49603 10 613 30841 7...
output:
1915598573008513
result:
ok single line: '1915598573008513'
Test #17:
score: 5
Accepted
time: 19ms
memory: 30204kb
input:
100000 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 314 3...
output:
94625535409026
result:
ok single line: '94625535409026'
Test #18:
score: 5
Accepted
time: 32ms
memory: 30136kb
input:
100000 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 2050 205...
output:
99469079815450
result:
ok single line: '99469079815450'
Test #19:
score: 5
Accepted
time: 240ms
memory: 79392kb
input:
1000000 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 1003 10...
output:
969470905350325
result:
ok single line: '969470905350325'
Test #20:
score: 5
Accepted
time: 215ms
memory: 78848kb
input:
1000000 15023 15023 15023 15023 15023 15023 15023 15023 15023 15023 15023 15023 15023 15023 15023 15...
output:
1003927881833136
result:
ok single line: '1003927881833136'
Extra Test:
score: 0
Extra Test Passed