ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201872 | #61. sequence | Kidding_Ma | 100 | 289ms | 1332kb | C++ | 2.8kb | 2024-02-07 15:37:44 | 2024-02-07 15:37:45 |
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#define maxn 100005
#define LL long long
using namespace std;
/*
dp[i][a][b][0] = max(dp[i-1][a][b][0] , dp[i-1][a-1][b][0] + A[i]);
dp[i][a][b][1] = max(dp[i-1][a][b][1] + A[i] , dp[i-1][a][b-1][1]
, dp[i-1][a][b][0] + A[i] , dp[i-1][a][b-1][0]);
dp[i][a][b][2] = max(dp[i-1][a][b][2] , dp[i-1][a-1][b][2] + A[i]
, dp[i-1][a][b][1] , dp[i-1][a-1][b][1] + A[i])
acquiesce length >= 1
*/
int n,k,A[maxn];
LL dp[2][12][12][3];
int g[2][12][12][3][2],c1[maxn],c2[maxn],cc1,cc2;
inline void check(LL &a,LL b,int g1[2],int g2[2],int add)
{
if(a <= b)
{
g1[0] = g2[0] , g1[1] = g2[1];
a = b;
if(add != -1)
{
if(g1[0] == -1) g1[0] = add;
else g1[1] = add;
}
}
}
inline bool cmp1(const int &u,const int &v){ return A[u] < A[v]; }
inline bool cmp2(const int &u,const int &v){ return A[u] > A[v]; }
inline bool cmp3(const int &u,const int &v){ return u > v; }
int main()
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%d",&A[i]);
int now=1,pre=0;
memset(dp[pre],-0x3f,sizeof dp[pre]);
memset(g,-1,sizeof g);
dp[pre][0][0][0] = 0;
for(int i=1;i<=n+1;i++,swap(now,pre))
{
memset(dp[now],-0x3f,sizeof dp[now]);
memset(g[now],-1,sizeof g[now]);
for(int a=0;a<=k;a++)
for(int b=0;b<=k;b++)
{
check(dp[now][a][b][0] , dp[pre][a][b][0] , g[now][a][b][0] , g[pre][a][b][0] , -1);
if(i<=n)check(dp[now][a+1][b][0] , dp[pre][a][b][0] + A[i] ,
g[now][a+1][b][0] , g[pre][a][b][0] , -1);
check(dp[now][a][b][1] , dp[pre][a][b][1]+A[i] , g[now][a][b][1] , g[pre][a][b][1] , -1);
if(i<=n)check(dp[now][a][b+1][1] , dp[pre][a][b][1] , g[now][a][b+1][1] , g[pre][a][b][1] , -1);
check(dp[now][a][b][1] , dp[pre][a][b][0] + A[i] , g[now][a][b][1] , g[pre][a][b][0] , i);
if(i<=n)check(dp[now][a][b+1][1] , dp[pre][a][b][0] , g[now][a][b+1][1] , g[pre][a][b][0] , i);
check(dp[now][a][b][2] , dp[pre][a][b][2] , g[now][a][b][2] , g[pre][a][b][2] , -1);
if(i<=n)check(dp[now][a+1][b][2] , dp[pre][a][b][2] + A[i] , g[now][a+1][b][2] , g[pre][a][b][2] , -1);
check(dp[now][a][b][2] , dp[pre][a][b][1] , g[now][a][b][2] , g[pre][a][b][1] , i-1);
if(i<=n)check(dp[now][a+1][b][2] , dp[pre][a][b][1] + A[i] , g[now][a+1][b][2] , g[pre][a][b][1] , i-1);
}
}
int Minloc = 0;
for(int i=1;i<=k;i++)
if(dp[pre][Minloc][Minloc][2] < dp[pre][i][i][2])
Minloc = i;
int l = g[pre][Minloc][Minloc][2][0] , r = g[pre][Minloc][Minloc][2][1];
for(int i=1;i<=n;i++)
{
if(i>=l && i<=r) c1[cc1++] = i;
else c2[cc2++] = i;
}
sort(c1,c1+cc1,cmp1);
sort(c2,c2+cc2,cmp2);
sort(c1,c1+Minloc,cmp3);
sort(c2,c2+Minloc,cmp3);
printf("%lld %d\n",dp[pre][Minloc][Minloc][2] , Minloc);
for(int i=0;i<Minloc;i++)
printf("%d %d\n",c1[i],c2[i]);
printf("%d %d\n",l,r);
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 552kb
input:
9 6 90513232 547369237 29366973 963238646 508659083 197312949 -388136260 839063142 514376598
output:
3689899860 1 7 1 2 9
result:
ok Correct!
Test #2:
score: 10
Accepted
time: 0ms
memory: 556kb
input:
10 3 -148714441 -773226103 351785224 873402083 964619994 955124079 -590107904 -534586469 -144883305 ...
output:
3144931380 0 3 6
result:
ok Correct!
Test #3:
score: 10
Accepted
time: 0ms
memory: 556kb
input:
896 10 -103258000 -267161128 342049077 -576014424 -251468123 -258154726 532328252 -136555726 -855120...
output:
34734718231 10 640 887 622 861 557 411 556 182 547 180 506 166 497 73 479 40 458 38 454 37 442 651
result:
ok Correct!
Test #4:
score: 10
Accepted
time: 1ms
memory: 560kb
input:
829 5 -736572685 732020370 60109046 892631666 -598811858 744210292 -741135695 252424944 -897618739 -...
output:
17323620468 5 59 758 35 623 34 601 33 305 29 182 12 70
result:
ok Correct!
Test #5:
score: 10
Accepted
time: 2ms
memory: 556kb
input:
1000 10 -146246732 -839681156 -138239993 911487408 116066094 97240933 852801575 -49047630 573040952 ...
output:
31711559641 10 227 968 192 943 187 899 182 839 140 829 138 479 114 425 106 335 94 266 93 40 77 248
result:
ok Correct!
Test #6:
score: 10
Accepted
time: 20ms
memory: 956kb
input:
51802 1 460031549 17261281 -493373332 -295361880 113022619 -288916664 11067353 -201350752 770468634 ...
output:
40529819515 1 29740 14486 29537 29840
result:
ok Correct!
Test #7:
score: 10
Accepted
time: 28ms
memory: 1172kb
input:
79111 1 -736675260 584393324 432351054 184812559 -54299869 -732773262 -724040719 -392301283 -5402913...
output:
33755742626 1 28887 52224 27858 29268
result:
ok Correct!
Test #8:
score: 10
Accepted
time: 32ms
memory: 1332kb
input:
100000 1 413895731 -867170142 46183962 954743605 -582068473 -499660757 -582356140 440310396 19028390...
output:
33766210686 1 44585 92821 44452 45048
result:
ok Correct!
Test #9:
score: 10
Accepted
time: 161ms
memory: 1332kb
input:
100000 10 866149389 -394971884 703119433 -8929233 442012074 -553957452 989992199 -258881087 88432484...
output:
54833163788 10 73670 80153 73617 65963 73616 65748 73550 57673 73518 44012 73466 35212 73358 34262 7...
result:
ok Correct!
Test #10:
score: 10
Accepted
time: 45ms
memory: 1140kb
input:
75414 4 516339273 -325212966 84971077 19447127 706751421 -388264011 277570310 857090528 266804338 37...
output:
45112654005 4 14999 73025 14907 56652 14796 36631 14637 1414 14325 15096
result:
ok Correct!