QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103993#6401. Classic: N Real DNA PotsHe_Ren#WA 2ms3764kbC++14804b2023-05-08 09:41:092023-05-08 09:41:12

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-08 09:41:12]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3764kb
  • [2023-05-08 09:41:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ldb;
typedef pair<int,int> pii;
const int MAXN = 1e5 + 5;

int n,d;
array<int,2> p[MAXN];

ldb calc(int i,int j)
{
	return ldb(p[i][1] - p[j][1]) / (p[i][0] - p[j][0]);
}

bool check(ldb lim)
{
	static int sta[MAXN], f[MAXN];
	int tp = 0;
	for(int i=n; i>=1; --i)
	{
		f[i] = 1;
		while(tp && calc(i, sta[tp]) >= lim)
			f[i] = max(f[i], f[sta[tp]] + 1), --tp;
		sta[++tp] = i;
		if(f[i] >= d) return 1;
	}
	return 0;
}

int main(void)
{
	scanf("%d%d",&n,&d);
	for(int i=1; i<=n; ++i)
		scanf("%d%d",&p[i][0],&p[i][1]);
	
	ldb l = -1e9, r = 1e9;
	for(int T=1; T<=100; ++T)
	{
		ldb mid = (l+r)/2;
		if(check(mid)) l = mid;
		else r = mid;
	}
	printf("%.20lf\n",l);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
1 2
2 4
3 3
4 1

output:

-1.00000000000000000000

result:

ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3540kb

input:

2 2
1 1
5 3

output:

0.50000000000000000000

result:

ok found '0.5000000', expected '0.5000000', error '0.0000000'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3764kb

input:

2 2
222640995 547139825
489207317 725361095

output:

0.66858134464563001575

result:

ok found '0.6685813', expected '0.6685813', error '0.0000000'

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3744kb

input:

1000 20
545612 774435015
828317 212155588
5294705 85926095
5648835 764528941
6159263 570820268
7177330 744079287
8446124 162286636
8735551 586528841
9263030 524140841
9505706 636254627
12111352 182639083
12750780 238494418
13149143 913232250
13382784 11485121
13699797 414697815
14263990 423817548
15...

output:

-0.05148693990004837157

result:

wrong answer 1st numbers differ - expected: '3.7932105', found: '-0.0514869', error = '1.0135734'