QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376215 | #4571. Even Split | InfinityNS# | WA | 0ms | 3860kb | C++14 | 2.1kb | 2024-04-04 00:02:01 | 2024-04-04 00:02:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=100050;
int l,n;
int a[N],x[N];
int L[N],R[N];
int maxSteps,steps;
bool Check(int mn,int mx,bool reconstruct=false){
x[0]=0;x[n]=l;
L[0]=R[0]=0;
a[n+1]=l;
for(int i=1;i<=n;i++){
L[i]=max(L[i-1]+mn,a[i]);
R[i]=min(R[i-1]+mx,a[i+1]);
if(L[i]>R[i])return false;
}
if(R[n]<l)return false;
if(reconstruct){
//for(int i=1;i<=n;i++){
// printf("L:%i R:%i\n",L[i],R[i]);
//}
for(int i=n-1;i>=1;i--){
x[i]=max(L[i],x[i+1]-mx);
}
}
return true;
}
int Get(int mn,bool reconstruct=false){
int top=l,bot=mn,ans=l;
while(top>=bot){
int mid=top+bot>>1;
if(Check(mn,mid)){
top=mid-1;
ans=mid;
}else{
bot=mid+1;
}
}
if(reconstruct){
Check(mn,ans,true);
}
return ans-mn;
}
void Solve(){
int bot=1,ans=l/n,top=ans-1;
while(top>=bot){
int mid=top+bot>>1;
int best1=Get(mid);
int best2=Get(mid+1);
if(best2<best1){
bot=mid+1;
}else{
top=mid-1;
ans=mid;
}
}
//printf("mn:%i diff:%i\n",ans,Get(ans));
Get(ans,true);
/*x[0]=0;x[n]=l;
for(int i=1;i<n;i++){
x[i]=a[i];
}
steps=0;
while(true){
steps++;
bool change=false;
for(int i=n-1;i>=1;i--){
int newX=max(a[i],min(a[i+1],(x[i-1]+x[i+1])/2));
if(newX!=x[i])change=true;
}
if(!change)break;
}
maxSteps=max(maxSteps,steps);*/
}
const int mxn=1e5;
const int mxl=1e9;
mt19937 rng(time(0));
void Gen(){
n=rng()%mxn+1;
l=rng()%(mxl-n-1)+n+1;
set<int> used;
auto Bad=[&](int x){
return x<=0 || x>=l || used.count(x);
};
for(int i=1;i<=n;i++){
a[i]=rng()%(l-1)+1;
int j=0;
while(Bad(a[i]+j) && Bad(a[i]-j)){
j++;
}
if(Bad(a[i]+j))a[i]-=j;
else a[i]+=j;
used.insert(a[i]);
}
sort(a+1,a+1+n);
}
const int tests=1e3;
void Test(){
for(int test=0;test<tests;test++){
Gen();
printf("generated test %i\n",test);
Solve();
printf("test %i: %i\n",test,steps);
}
printf("%i\n",maxSteps);
}
int main(){
//Test();
scanf("%i %i",&l,&n);
for(int i=1;i<=n;i++)scanf("%i",&a[i]);
Solve();
for(int i=1;i<=n;i++)printf("%i %i\n",x[i-1],x[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
6 3 1 3 5
output:
0 2 2 4 4 6
result:
ok Minimal imbalance is 0
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
10 2 1 2
output:
0 2 2 10
result:
ok Minimal imbalance is 6
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3856kb
input:
100 10 14 26 29 31 34 42 44 48 49 68
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100
result:
wrong answer Participant do not output valid split, first problem in segment 0 (non-positive length)