This commit is contained in:
Zengtudor 2024-08-12 17:03:07 +08:00
parent 154e9beea2
commit 30d8749774
2 changed files with 65 additions and 1 deletions

View File

@ -0,0 +1,60 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Node{
int l,r,s;
};
const int MAX_N = 505;
int n,pn=0;
int a[MAX_N];
int ans[MAX_N];
int changed=0;
Node node[MAX_N*MAX_N];
int readint();
signed main(signed argc,char *argv[]){
n=readint();
for(int i=1;i<=n;i++){
a[i]=readint();
}
for(int i=1;i<=n;i++){
int cnt=0;
for(int j=i;j<=n;j++){
cnt+=a[j];
node[++pn] = {
i,j,cnt
};
}
}
sort(node+1,node+1+pn,[](Node a,Node b)->bool{
return a.s<b.s;
});
int pmincmplast = INT_MAX;
for(int i=1;i<pn;i++){
for(int j=node[i].l;j<=node[i].r;j++){
if (ans[j]==0) {
abs(node[i].s-node[i+1].s);
}else{
ans[j]=min(abs(node[i].s-node[i+1].s),ans[j]);
}
}
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<endl;
}
}
int readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}

View File

@ -113,3 +113,7 @@ target("U178578")
local s=tostring(v) local s=tostring(v)
add_tests(s,{files="./day10/U178578/*.cpp",runargs={"bubble"..s..".in","bubble"..s..".ans"},run_timeout=1000,defines="OITEST"}) add_tests(s,{files="./day10/U178578/*.cpp",runargs={"bubble"..s..".in","bubble"..s..".ans"},run_timeout=1000,defines="OITEST"})
end end
target("P9127")
set_rundir("./day9/P9127")
add_files("./day9/P9127/*.cpp")