QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#507486 | #2338. Beautiful Bridges | flying | WA | 0ms | 3988kb | C++14 | 994b | 2024-08-06 18:15:05 | 2024-08-06 18:15:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e4+5;
int dp[N], x[N], y[N], n, h;
bool can[N][N];
int dist(int x1,int y1,int x2,int y2)
{
return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
}
bool check(int l,int r)
{
int lim=2*h-(x[r]-x[l]);
for(int i=l;i<=r;i++)
if(y[i]*2>lim && dist(x[i]*2,y[i]*2,x[l]+x[r],lim)>(x[r]-x[l])*(x[r]-x[l]))
return false;
return true;
}
signed main()
{
int a,b;
cin >> n >> h >> a >> b;
for(int i=1;i<=n;i++)
scanf("%lld %lld",&x[i],&y[i]);
int r=1;
for(int i=1;i<n;i++)
{
while(r+1<=n && check(i,r+1))
r++;
if(r==i)
{
printf("impossible\n");
return 0;
}
for(int j=i+1;j<=r;j++)
can[i][j]=true;
}
memset(dp,0x3f,sizeof(dp));
dp[1]=a*(h-y[1]);
for(int i=2;i<=n;i++)
for(int j=i-1;j>=1;j--)
if(can[j][i])
dp[i]=min(dp[i],dp[j]+a*(h-y[i])+b*(x[i]-x[j])*(x[i]-x[j]));
else
break;
printf("%lld\n",dp[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3988kb
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: 3800kb
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: 0ms
memory: 3936kb
input:
2 1 1 1 0 0 2 0
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
2 1 1 1 0 0 3 0
output:
impossible
result:
ok single line: 'impossible'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3892kb
input:
4 5 100 1 0 0 1 3 9 3 10 0
output:
impossible
result:
wrong answer 1st lines differ - expected: '1100', found: 'impossible'