QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#772437 | #4571. Even Split | lijunrui08 | WA | 0ms | 3964kb | C++14 | 1.4kb | 2024-11-22 19:34:18 | 2024-11-22 19:34:19 |
Judging History
answer
#include <bits/stdc++.h>
#define fo(i,x,y) for(register int i=(x);i<=(y);i++)
#define de(i,x,y) for(register int i=(x);i>=(y);i--)
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const ll N=1e5+50,M=+50,L=0;
const ll P=0,inf=1e9;
inline ll read(){
ll x=0;bool f=0;char c=getchar();
while(c<'0'||c>'9') f|=(c=='-'),c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
int len,n;
int a[N],lres[N],rres[N];
int check2(int mn,int ans){
int lp=0,rp=0,mx=mn+ans;
fo(i,1,n){
if(rp+mx-1<a[i]) return 0;
if(lp+mn-1>a[i+1]) return 2;
rp=min(rp+mx-1,a[i+1]);
lp=max(lp+mn-1,a[i]);
lres[i]=lp,rres[i]=rp;
}
if(rp<len) return 0;
return 1;
}
int check1(int ans){
int l=0,r=1e9;
while(l<=r){
int mid=(l+r)>>1;
int res=check2(mid,ans);
if(res==1) return mid;
if(res==2) r=mid-1;
else l=mid+1;
}
return 0;
}
signed main(){
len=read(),n=read();
fo(i,1,n) a[i]=read();
a[n+1]=len;
int l=0,r=1e9,ans,mn;
while(l<=r){
int mid=(l+r)>>1,w;
if(w=check1(mid)) ans=mid,mn=w,r=mid-1;
else l=mid+1;
}
check2(mn,ans);
lres[n]=len;
de(i,n-1,1) if(lres[i]-lres[i-1]+1<mn)
lres[i-1]-=mn-(lres[i]-lres[i-1]+1);
// if(len==999927360&&a[1]==2777) cout<<ans<<endl;
fo(i,1,n) printf("%d %d\n",lres[i-1],lres[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3964kb
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: 3908kb
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: 3824kb
input:
100 10 14 26 29 31 34 42 44 48 49 68
output:
0 14 14 26 26 29 29 32 32 35 35 42 42 45 45 48 48 51 51 100
result:
wrong answer Jury found better solution (j=29 vs p=46)