QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363555 | #2338. Beautiful Bridges | TWTP_TCTF | WA | 1ms | 9848kb | C++14 | 2.0kb | 2024-03-24 00:18:20 | 2024-03-24 00:18:20 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 1e4 + 2, MOD = 998244353;
int x[N], y[N];
bitset<N> L[N], R[N];
bool in_side(int x0, int y0, int r, int a, int b) {
if (b <= y0)return true;
int dx = x0 - a;
int dy = y0 - b;
return 1ll * dx * dx + 1ll * dy * dy <= 1ll * r * r;
}
ll dp[N];
void doWork() {
int n, h, a, b;
cin >> n >> h >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 1; i <= n; i++) {
int j = i;
while (j < n) {
j++;
int x0 = x[i] + x[j]; // (xi + xj) / 2
int y0 = 2 * h - (x[j] - x[i]); // h - (xj - xi) / 2
if (!in_side(x0, y0, x[j] - x[i], x[j] * 2, y[j] * 2))break;
L[i][j] = 1;
}
}
for (int i = n; i >= 1; i--) {
int j = i;
while (j) {
j--;
int x0 = x[i] + x[j]; // (xi + xj) / 2
int y0 = 2 * h - (x[i] - x[j]); // h - (xj - xi) / 2
if (!in_side(x0, y0, x[i] - x[j], x[i] * 2, y[i] * 2))break;
R[j][i] = 1;
}
}
dp[1] = 1ll * (h - y[1]) * a;
for (int i = 2; i <= n; i++) {
dp[i] = 1e18;
int bst = 1;
for (int j = 1; j < i; j++) {
if (L[j][i] && R[j][i]) {
ll cost = 1ll * (h - y[i]) * a;
ll d = x[i] - x[j];
cost += 1ll * d * d * b;
dp[i] = min(dp[i], dp[j] + cost);
if (dp[i] == dp[j - 1] + cost) bst = j;
}
}
}
if (dp[n] < 1e18) {
cout << dp[n];
} else {
cout << "impossible";
}
}
int main() {
IO
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
doWork();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9848kb
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: 1ms
memory: 5620kb
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: 5688kb
input:
2 1 1 1 0 0 2 0
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
2 1 1 1 0 0 3 0
output:
impossible
result:
ok single line: 'impossible'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 5684kb
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'