QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398840 | #2338. Beautiful Bridges | BIXIAN | WA | 1ms | 4256kb | C++14 | 1.6kb | 2024-04-25 19:00:35 | 2024-04-25 19:00:36 |
Judging History
answer
#include<iostream>
#include<algorithm>
using namespace std;
int f[100001];
long long n, h, a, d,ans;
long long s[100001][2];
long long qw[10002],qe[10002];
bool df(int a, int b)
{
long long midy = 10*h - 5*(b - a);
if (midy < 10*f[a] || midy < 10*f[b])
return 0;
long long midx = (a + b)*5;
long long r = (b -a)*5;
r *= r;
for (int i = a; i <= b; i++)
{
if (f[i]>=0)
{
if ((10*f[i]>=midy)&&((midx - 10*i) * (midx - 10*i) + (midy - 10*f[i]) * (midy - 10*f[i]))>r)
return 0;
}
}
return 1;
}
int vv = 0;
long long min1 = -1,mn;
void dfs()
{
for (int i = 2; i <= ans; i++)
{
for (int u = i-1; u>=1; u--)
{
if (qe[i] && (((s[i][0] - s[u][0]) * (s[i][0] - s[u][0])) - qe[i] > mn))
break;
if (qw[u]&&(df(s[u][0], s[i][0])))
{
if (!qw[i])
{
qw[i] = qw[u] + d * ((s[i][0] - s[u][0]) * (s[i][0] - s[u][0])) + s[i][1];
qe[i]=((s[i][0] - s[u][0])* (s[i][0] - s[u][0]));
}
else
{
qw[i] = min(qw[i], qw[u] + d * ((s[i][0] - s[u][0]) * (s[i][0] - s[u][0])) + s[i][1]);
qe[i] = ((s[i][0] - s[u][0]) * (s[i][0] - s[u][0]));
}
if (i == ans)
{
if (min1 > qw[i]||min1==-1)
min1 = qw[i];
vv = 1;
}
}
}
}
}
int main()
{
cin >> n >> h >> a >> d;
int x,fr;
ans = n;
for (int i = 1; i <= 100000; i++)
f[i] = -1;
for (int i = 1; i <= n; i++)
{
scanf("%d", &x);
scanf("%d", &f[x]);
s[i][0] = x;
s[i][1] = a * (h - f[s[i][0]]);
}
qw[1] = s[1][1];
mn = h * a;
dfs();
if (!vv)
cout << "impossible";
if(vv)
cout << min1 << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4220kb
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: 4256kb
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: 4040kb
input:
2 1 1 1 0 0 2 0
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4168kb
input:
2 1 1 1 0 0 3 0
output:
impossible
result:
ok single line: 'impossible'
Test #5:
score: 0
Accepted
time: 1ms
memory: 4168kb
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: 4228kb
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: 4172kb
input:
2 100000 10000 10000 0 0 100000 0
output:
100002000000000
result:
ok single line: '100002000000000'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4044kb
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: 4048kb
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:
2141
result:
wrong answer 1st lines differ - expected: '2134', found: '2141'