QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#772351#4571. Even Splitlijunrui08WA 0ms3928kbC++141.3kb2024-11-22 18:56:002024-11-22 18:56:01

Judging History

你现在查看的是最新测评结果

  • [2024-11-22 18:56:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3928kb
  • [2024-11-22 18:56:00]
  • 提交

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<a[i]) return 0;
		if(lp+mn>a[i+1]) return 2;
		rp=min(rp+mx,a[i+1]);
		lp=max(lp+mn,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);
	fo(i,1,n) printf("%d %d\n",rres[i-1],rres[i]);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3928kb

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: 3732kb

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: 3800kb

input:

100 10
14 26 29 31 34 42 44 48 49 68

output:

0 26
26 29
29 31
31 34
34 42
42 44
44 48
48 49
49 68
68 100

result:

wrong answer Jury found better solution (j=29 vs p=31)