QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#399326 | #2338. Beautiful Bridges | BIXIAN | WA | 2ms | 7184kb | C++14 | 1.9kb | 2024-04-26 10:27:03 | 2024-04-26 10:27:03 |
Judging History
answer
#include<iostream>
#include<algorithm>
using namespace std;
int f[100001];
long long n, h, a, d,ans, min1 = -1;
long long s[100001][2], qw[10002];
bool vv = 0;
struct po
{
int a, b, max1 = -1;
}s1[200002];
int bul(int le, int ri, int i)
{
if (le == ri)
{
s1[i].max1 = f[le];
return f[le];
}
int a1 = bul(le, (le + ri) / 2, 2 * i);
int a2 = bul((le + ri) / 2 + 1, ri, 2 * i + 1);
if (a1 < a2)
a1 = a2;
s1[i].max1 = a1;
s1[i].a = le;
s1[i].b = ri;
return a1;
}
bool fin(int le, int ri, long long y, long long x, long long r,int i)
{
if (2*s1[i].max1 < y)
return 1;
if (le == ri)
{
if (((x - (le*2)) * (x - (le*2)) + (y - (f[le]*2)) * (y - (f[le]* 2))) > r)
return 0;
return 1;
}
return (fin(le, (le + ri) / 2, y, x, r, 2 * i) && fin((le + ri) / 2 + 1, ri, y, x, r, 2 * i + 1));
}
bool df(int a, int b)
{
long long midy = (h*2) -(b - a);
if (midy < (f[a]*2) || midy < (f[b]*2))
return 0;
long long midx = (a + b);
long long r = (b -a);
r *= r;
return fin(a, b, midy, midx, r, 1);
}
void dfs()
{
for (int i = 2; i <= ans; i++)
{
for (int u = i-1; u>=1; u--)
{
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];
else
qw[i] = min(qw[i], qw[u] + d * ((s[i][0] - s[u][0]) * (s[i][0] - s[u][0])) + s[i][1]);
if (i == ans)
{
if (min1 > qw[i]||min1==-1)
min1 = qw[i];
vv = 1;
}
}
}
}
}
int main()
{
cin >> n >> h >> a >> d;
int x,fr=0;
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]]);
if (x > fr)
fr = x;
}
bul(1, fr, 1);
qw[1] = s[1][1];
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: 6564kb
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: 6568kb
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: 2ms
memory: 6500kb
input:
2 1 1 1 0 0 2 0
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 6572kb
input:
2 1 1 1 0 0 3 0
output:
impossible
result:
ok single line: 'impossible'
Test #5:
score: 0
Accepted
time: 0ms
memory: 6384kb
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: 6500kb
input:
4 5 1 100 0 0 1 3 9 3 10 0
output:
10010
result:
ok single line: '10010'
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 7184kb
input:
2 100000 10000 10000 0 0 100000 0
output:
8590034594000000000
result:
wrong answer 1st lines differ - expected: '100002000000000', found: '8590034594000000000'