ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#199401 | #156. 排序 | tkswls | 100 | 144ms | 24312kb | C++11 | 959b | 2023-12-14 11:34:07 | 2023-12-14 15:59:51 |
answer
#include <bits/stdc++.h>
using namespace std;
int n, sa[100005], rk[100005], w[100005][30], f[100005][27], maxn[30];
long long x;
inline int rd() {
x = (100000005 * x + 1532777326) % 998244353;
return x / 100;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> sa[i];
rk[sa[i]] = i;
}
rk[n + 1] = -1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 26; j++) {
w[i][j] = rd() % 10000;
}
}
for (int i = 1; i <= 26; i++) {
f[1][i] = w[sa[1]][i];
maxn[i] = max(maxn[i - 1], f[1][i]);
}
int op;
maxn[0] = -0x3f3f3f3f;
f[1][0] = -0x3f3f3f3f;
for (int i = 2; i <= n; i++) {
if (rk[sa[i] + 1] > rk[sa[i - 1] + 1]) op = 0;
else op = 1;
for (int j = 1; j <= 26; j++) {
f[i][j] = maxn[j - op] + w[sa[i]][j];
}
for (int j = 1; j <= 26; j++) {
maxn[j] = max(maxn[j - 1], f[i][j]);
}
}
cout << maxn[26];
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1272kb
input:
5 9301595 2 1 4 5 3
output:
46973
result:
ok single line: '46973'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1276kb
input:
3 770073280 1 3 2
output:
29041
result:
ok single line: '29041'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1272kb
input:
12 283241706 5 3 1 9 12 8 6 11 10 2 7 4
output:
103016
result:
ok single line: '103016'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1276kb
input:
15 479820599 13 14 5 4 3 8 9 1 6 10 12 11 15 2 7
output:
126942
result:
ok single line: '126942'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1500kb
input:
1000 355104363 1000 999 998 997 996 388 605 389 606 220 951 430 390 607 221 863 137 677 317 952 431 ...
output:
5764492
result:
ok single line: '5764492'
Test #6:
score: 10
Accepted
time: 0ms
memory: 1504kb
input:
1000 366293829 1000 69 451 657 551 743 190 984 70 564 392 824 532 986 81 66 295 765 896 623 163 884 ...
output:
5600426
result:
ok single line: '5600426'
Test #7:
score: 10
Accepted
time: 47ms
memory: 24312kb
input:
100000 371247896 35347 1572 50361 8001 95917 35348 1573 97979 50362 41752 65318 56510 73373 22823 71...
output:
507072022
result:
ok single line: '507072022'
Test #8:
score: 10
Accepted
time: 34ms
memory: 24308kb
input:
100000 458332973 19299 92398 31586 14112 74310 46708 46589 23279 79827 56888 43591 92936 19300 5900 ...
output:
505713981
result:
ok single line: '505713981'
Test #9:
score: 10
Accepted
time: 27ms
memory: 16664kb
input:
66760 945496030 5000 4246 42979 28646 49737 57862 35793 5001 52294 6333 51711 44038 19248 54950 4362...
output:
338691057
result:
ok single line: '338691057'
Test #10:
score: 10
Accepted
time: 36ms
memory: 18560kb
input:
75005 736928528 8914 64645 23160 17625 64151 66600 17956 40874 57882 17987 53420 9371 71736 59142 39...
output:
378453236
result:
ok single line: '378453236'