ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196579 | #2846. 分割 divide | tkswls | 100 | 157ms | 84848kb | C++11 | 970b | 2023-10-28 11:34:16 | 2023-10-28 12:06:43 |
answer
#include<bits/stdc++.h>
using namespace std;
int n, m;
int a[100005], ls[100005], cnt, la[100005], pre[100005];
int f[100005][105], g[100005][105];
void init() {
sort(ls + 1, ls + n + 1);
for (int i = 1; i <= n; i++) {
if (ls[i] != ls[i - 1]) {
ls[++cnt] = ls[i];
}
}
}
int finds(int p) {
return lower_bound(ls + 1, ls + cnt + 1, p) - ls;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ls[i] = a[i];
}
init();
for (int i = 1; i <= n; i++) {
int p = finds(a[i]);
if (la[p] == 0) {
pre[i] = -1;
la[p] = i;
} else {
pre[i] = la[p];
la[p] = i;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= min(m, i); j++) {
f[i][j] = g[i - 1][j - 1] + 1;
if (pre[i] != -1) {
f[i][j] = max(f[i][j], f[pre[i]][j] + 1);
}
g[i][j] = max(f[i][j], g[i - 1][j]);
}
}
cout << g[n][m];
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1356kb
input:
100 50 207579013 207579013 1361956 207579013 1361956 207579013 207579013 1361956 1361956 1361956 136...
output:
100
result:
ok single line: '100'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1360kb
input:
100 20 628145517 628145517 1361956 1361956 1361956 1361956 207579013 1361956 628145517 628145517 207...
output:
65
result:
ok single line: '65'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1356kb
input:
100 5 883515281 762888636 186969586 1361956 1361956 883515281 98152103 207579013 158176573 326402540...
output:
27
result:
ok single line: '27'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1524kb
input:
300 30 628145517 186969586 158176573 158176573 376140463 883515281 186969586 186969586 186969586 326...
output:
107
result:
ok single line: '107'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1688kb
input:
500 100 207579013 883515281 883515281 1361956 1361956 883515281 376140463 1361956 628145517 1361956 ...
output:
302
result:
ok single line: '302'
Test #6:
score: 10
Accepted
time: 15ms
memory: 43084kb
input:
50000 100 356184445 743898207 645453896 66699171 491536716 644644279 353829455 956650281 698822011 9...
output:
138
result:
ok single line: '138'
Test #7:
score: 10
Accepted
time: 55ms
memory: 84848kb
input:
100000 100 894188676 772960004 643832561 222908206 680998757 532523911 585748368 153827296 262586878...
output:
183
result:
ok single line: '183'
Test #8:
score: 10
Accepted
time: 0ms
memory: 9600kb
input:
10000 50 432878830 328373828 692477849 604051154 711659178 202255340 444310469 925786548 913989446 8...
output:
170
result:
ok single line: '170'
Test #9:
score: 10
Accepted
time: 33ms
memory: 84468kb
input:
100000 80 403573724 1738704 210461043 643215696 799313373 896162464 747545899 877444310 775142615 55...
output:
2051
result:
ok single line: '2051'
Test #10:
score: 10
Accepted
time: 54ms
memory: 84472kb
input:
100000 100 472616392 943436881 219485654 785511732 734460159 153203339 184483001 890357495 425782009...
output:
676
result:
ok single line: '676'
Extra Test:
score: 0
Extra Test Passed