UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196578#2846. 分割 dividesnow_trace1001380ms90116kbC++11887b2023-10-28 11:31:142023-10-28 12:06:39

answer

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
#define endl '\n'
int mn[100005],tag[100005],a[100005];
int dp[100005][105],mx[100005][105];
vector<int>pos[100005];
int n,m;
signed main(){
	cin >> n >> m;
	for(int i = 1;i<=n;i++)cin >> a[i];
	vector<int>p;
	for(int i = 1;i<=n;i++){
		p.push_back(a[i]);
	}sort(p.begin(),p.end());p.erase(unique(p.begin(),p.end()),p.end());
	for(int i = 1;i<=n;i++){
		a[i] = lower_bound(p.begin(),p.end(),a[i])-p.begin()+1;
		pos[a[i]].push_back(i);
	}for(int j = 1;j<=m;j++){
		memset(mn,0,sizeof(mn));memset(tag,0,sizeof(tag));
		for(int i = 1;i<=n;i++){
			mn[a[i]] = max(mn[a[i]],mx[i-1][j-1]-tag[a[i]]);tag[a[i]]++;
			dp[i][j] = mn[a[i]]+tag[a[i]];
			mx[i][j] = max(mx[i-1][j],dp[i][j]);
		}
	}int ans =0;
	for(int i = 1;i<=n;i++){
		ans = max(ans,dp[i][m]);
	}cout << ans << endl;
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 4472kb

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: 4476kb

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: 4472kb

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: 4ms
memory: 4640kb

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: 7ms
memory: 4808kb

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: 176ms
memory: 47288kb

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: 453ms
memory: 90116kb

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: 19ms
memory: 12756kb

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: 320ms
memory: 87476kb

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: 401ms
memory: 87736kb

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