This commit is contained in:
Zengtudor 2024-08-05 14:31:16 +08:00
parent 8e12d21543
commit 8ba99ff337
4 changed files with 157 additions and 5 deletions

2
.gitignore vendored
View File

@ -41,3 +41,5 @@ day3/afternoon/operator
day3/T490194/T490194
day3/T433080/redo
day3/T433080/out.txt
day2/U111091/out.txt
day2/U111091/fixed

57
day2/U111091/fixed.cpp Normal file
View File

@ -0,0 +1,57 @@
#include<bits/stdc++.h>
using namespace std;
typedef int i32;
typedef unsigned int u32;
#ifdef DEBUG
#define PRINT_VALUE(v){using namespace std;cout<<#v<<" :"<<v<<endl;}
#endif
#ifndef DEBUG
#define PRINT_VALUE(v)
#endif
const i32 MAX_N=5'0000;
i32 t,n,k,m;
u32 x[MAX_N],perfix[MAX_N+5];
template<typename T>
void set_mem(T *begin,u32 size,T value){
for(u32 i=0;i<size;i++){
begin[i]=0;
}
}
u32 one_section(){
u32 max_num=0;
for(u32 i=1;i<=n;i++){
u32 j=1;
while(x[i+j]-x[i]>m){
j++;
}
j--;
max_num = max(max_num,perfix[i+j]-perfix[i]);
}
return max_num;
}
int main(){
cin>>t;
PRINT_VALUE(t);
return 0;
for(u32 i=1;i<=t;i++){
cin>>n>>k>>m;
set_mem(perfix, n+1, 0u);
for(u32 j=1;j<=n;j++){
cin>>x[i];
}
string s;
cin>>s;
for(u32 j=0;j<s.size();j++){
if (s[j]=='1') {
perfix[j+2] = perfix[j+1] + ( x[j+2] - x[j+1] );
}
}
u32 num = max(one_section(),(u32)0);
}
}

View File

@ -1,5 +0,0 @@
54
72
0
1
0

View File

@ -0,0 +1,98 @@
#include<bits/stdc++.h>
#define MAXN 200005
#define P int(1e9+7)
using namespace std;
typedef long long ll;
/*
U111091 2
k==1
1
k==2
1.
2. i2i之前和i之后
2
2使
case1
case2dp之后维护前缀/max
线
*/
int T,N,K,q;
int x[MAXN], sum = 0;
int g[MAXN], pre[MAXN], suf[MAXN];
char s[MAXN];
int solve1(int q)//解决优化一段长度为q的土路的情况
{
int k = 1;//一段路的开始位置
int ans = 0;//能优化的最长的土路的长度
int ans1;
for(int i=2;i<=N;i++)
{
while(x[i]-x[k]>q)
k++;
ans1 = g[i] - g[k]; //第k个村庄到第i个村庄之间土路的长度
if(s[k]=='1')
ans1 += q - (x[i]-x[k]);
ans = max(ans, ans1);
}
//cerr<<"ans1 = "<<ans1<<endl;
return ans;
}
int solve2(int q)//计算找两段长度为q的土路最多能改变多少变成高速公路
{
memset(pre, 0, sizeof(pre));
memset(suf, 0, sizeof(suf));
int ans1;
int k = 1;//一段路的开始位置
for(int i=2;i<=N;i++){
while(x[i]-x[k]>q) ++k;
ans1 = g[i] - g[k];
if(s[k]=='1')
ans1 += q - (x[i]-x[k]);
pre[i] = max(pre[i-1], ans1);
}
k = N;
for(int i=N-1;i>=1;i--){
while(x[k]-x[i]>q)
--k;
ans1 = g[k] - g[i];
if(s[k+1]=='1')
ans1 += q - (x[k]-x[i]);
suf[i] = max(suf[i+1], ans1);
}
int ans = 0;
for(int i=2;i<=N;i++){
ans = max(ans, pre[i] + suf[i]);
}
return ans;
}
int main(){
cin>>T;
while(T--){
cin>>N>>K>>q;
for(int i=1;i<=N;i++)
cin>>x[i];
cin>>s+2;
s[1] = '0';
sum = 0;//土路总长度
for(int i=2;i<=N;i++){
g[i] = g[i-1];//前i个村庄之间土路的总长度
if(s[i]=='1')//i-1到i村庄之间的路是土路
{
g[i] += x[i] - x[i-1];
sum += x[i] - x[i-1];
}
}
int ans;
if(K==1)
ans = sum - solve1(q);
else
ans = sum - max(solve1(2*q), solve2(q));
cout<<ans<<'\n';
}
return 0;
}