QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398744#2338. Beautiful BridgesBIXIANWA 1ms4092kbC++141.9kb2024-04-25 17:33:362024-04-25 17:33:37

Judging History

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

  • [2024-04-25 17:33:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4092kb
  • [2024-04-25 17:33:36]
  • 提交

answer

#include<iostream>
using namespace std;
int f[100001];
long long n, h, a, d,ans,w;
long long s[100001][2];
bool df(int a, int b)
{
	double midx = ((double)a + (double)b) / 2;
	double midy = h - ((double)b - (double)a) / 2;
	if (midy < f[a] || midy < f[b])
	{
		return 0;
	}
	double r = ((double)b - (double)a) / 2;
	for (int i = a; i <= b; i++)
	{
		if (f[i]>=0)
		{
			if ((f[i]>=midy)&&((midx - (double)i) * (midx - (double)i) + (midy - (double)f[i]) * (midy - (double)f[i]))>(r*r))
				return 0;
		}
	}
	return 1;
}
int vv = 0;
void dfs(int i)
{
	for (int j = i + 1; j <= ans; j++)
	{
		if ((df(s[i][0], s[j][0])))
		{
			s[i][1] = j;
			w += d * ((s[j][0] - s[i][0]) * (s[j][0] - s[i][0]))+a * (h - f[s[j][0]]);
			if (j == ans)
			{
				vv = 1;
				return;
			}
			dfs(j);
			if (vv)
				return;
			w -= d * ((s[j][0] - s[i][0]) * (s[j][0] - s[i][0]))+a * (h - f[s[j][0]]);
		}
	}
}
int main()
{
	cin >> n >> h >> a >> d;
	int max1 = 0,x,fr;
	for (int i = 1; i <= 100000; i++)
		f[i] = -1;
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		cin >> f[x];
		ans++;
		s[ans][0] = x;
		if (f[x] > max1)
			max1 = f[x];
	}
	w += a * (h - f[s[1][0]]);
	dfs(1);
	if (!vv)
		cout << "impossible";
	if(vv)
	{
		while (1)
		{
			int yy = 1;
			bool v = 1;
			while (yy != ans && s[yy][1] != ans)
			{
				if (df(s[yy][0], s[s[s[yy][1]][1]][0]))
				{
					long long qw = h - f[s[s[yy][1]][0]];
					long long qe = (s[s[s[yy][1]][1]][0] - s[yy][0]) * (s[s[s[yy][1]][1]][0] - s[yy][0]);
					long long qe1 = (s[s[s[yy][1]][1]][0] - s[s[yy][1]][0]) * (s[s[s[yy][1]][1]][0] - s[s[yy][1]][0]);
					long long qe2 = (s[s[yy][1]][0] - s[yy][0]) * ((s[s[yy][1]][0] - s[yy][0]));
					if (a * qw > d * (qe - qe1 - qe2))
					{
						v = 0;
						s[yy][1] = s[s[yy][1]][1];
						w -= a * qw - d * (qe - qe1 - qe2);
					}
				}
				yy = s[yy][1];
			}
			if (v)
				break;
		}
		cout << w;
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4028kb

input:

5 60 18 2
0 0
20 20
30 10
50 30
70 20

output:

6460

result:

ok single line: '6460'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4028kb

input:

4 10 1 1
0 0
1 9
9 9
10 0

output:

impossible

result:

ok single line: 'impossible'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3992kb

input:

2 1 1 1
0 0
2 0

output:

6

result:

ok single line: '6'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3972kb

input:

2 1 1 1
0 0
3 0

output:

impossible

result:

ok single line: 'impossible'

Test #5:

score: 0
Accepted
time: 0ms
memory: 4020kb

input:

4 5 100 1
0 0
1 3
9 3
10 0

output:

1100

result:

ok single line: '1100'

Test #6:

score: 0
Accepted
time: 1ms
memory: 4088kb

input:

4 5 1 100
0 0
1 3
9 3
10 0

output:

10010

result:

ok single line: '10010'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3980kb

input:

2 100000 10000 10000
0 0
100000 0

output:

100002000000000

result:

ok single line: '100002000000000'

Test #8:

score: 0
Accepted
time: 1ms
memory: 4092kb

input:

13 43 1 5
3 26
4 25
10 23
11 0
23 2
49 20
64 2
68 0
83 24
84 17
91 33
92 6
97 33

output:

7348

result:

ok single line: '7348'

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 4040kb

input:

12 29 5 1
4 26
5 18
15 15
27 26
31 12
40 0
46 19
67 4
68 2
77 1
83 12
89 10

output:

2168

result:

wrong answer 1st lines differ - expected: '2134', found: '2168'