QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399327 | #2338. Beautiful Bridges | BIXIAN | WA | 2ms | 9364kb | C++14 | 1.9kb | 2024-04-26 10:28:33 | 2024-04-26 10:28:34 |
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[300002];
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9364kb
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: 7992kb
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: 9104kb
input:
2 1 1 1 0 0 2 0
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 2ms
memory: 9356kb
input:
2 1 1 1 0 0 3 0
output:
impossible
result:
ok single line: 'impossible'
Test #5:
score: 0
Accepted
time: 1ms
memory: 8448kb
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: 0ms
memory: 8384kb
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: 0ms
memory: 8396kb
input:
2 100000 10000 10000 0 0 100000 0
output:
100002000000000
result:
ok single line: '100002000000000'
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 8004kb
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:
impossible
result:
wrong answer 1st lines differ - expected: '7348', found: 'impossible'