QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#124942 | #5648. Crossing the Railways | Hongzy# | WA | 2ms | 3844kb | C++17 | 5.4kb | 2023-07-15 19:45:24 | 2023-07-15 19:45:24 |
Judging History
answer
#include <bits/stdc++.h>
#define LOG(FMT...) fprintf(stderr, FMT);
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
using db = double;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 mt(chrono::system_clock::now().time_since_epoch().count());
uniform_int_distribution<ll> ran(0, 1ll << 62);
void ucin() { ios::sync_with_stdio(0); cin.tie(0); }
// uniform_real_distribution<double> dbran;
template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }
template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }
inline ll sqr(ll x) { return x * x; }
inline ll cub(ll x) { return x * x * x; }
const int N = 510;
const int INF = 1e9;
const db eps = 1e-5;
#define lt(x, y) ((x) < (y) - eps)
#define leq(x, y) ((x) < (y) + eps)
struct seg {
int r, a, b;
bool operator < (const seg &rhs) const {
if(r != rhs.r) return r < rhs.r;
return a < rhs.a;
}
} a[N];
int n, m, s, v, L[12], R[12];
int dp[N*2], X[N*2], Y[N*2], tag[N*2];
bool inc(db l, db x, db r) {
return lt(l, x) && lt(x, r);
}
bool incLL(ll l, ll x, ll r) {
return l < x && x < r;
}
int find(int y, ll up) { //last <= y
if(!L[y]) return -1;
int l = L[y], r = R[y], ans = -1;
while(l <= r) {
int mid = (l + r) >> 1;
if(X[mid] <= up) l = (ans = mid) + 1;
else r = mid - 1;
}
return ans;
}
bool inc(db x1, int y1, db x2, int y2) {
// assert(lt(x1, x2) && y1 < y2);
db k = (x2 - x1) / (y2 - y1);
rep(i, y1, y2) {
db x0 = k * (i - y1) + x1;
int z = find(i, ll(x0));
if(z == -1) continue;
z = (z + 1) / 2;
if(inc(a[z].a, x0, a[z].b))
return true;
}
return false;
}
int ans;
void upd(int id, db k, int cur) {
rep(i, Y[id]+1, m+1) {
db x0 = k * (i - Y[id]) + X[id];
if(i == m+1) {
if(leq(x0, s)) {
ans = min(ans, cur);
}
break;
}
int z = find(i, ll(x0));
if(z == -1) continue;
int w = z + 1;
z = (z + 1) / 2;
if(inc(a[z].a, x0, a[z].b))
break;
if(Y[w] == i)
dp[w] = min(dp[w], cur + 1);
}
}
void DP(int id, int y0, db k, int cur) {
per(i, y0, 1) {
db x0 = k * (i - Y[id]) + X[id];
int z = find(i, ll(x0));
if(z == -1) continue;
int w = dp[z];
z = (z + 1) / 2;
if(inc(a[z].a, x0, a[z].b))
break;
cur = min(cur, w + 2);
}
dp[id] = min(dp[id], cur);
upd(id, k, cur);
}
int main() {
scanf("%d%d%d%d", &n, &m, &s, &v);
rep(i, 1, n) {
int a, b, r;
scanf("%d%d%d", &a, &b, &r);
::a[i] = {r, a, b};
}
sort(a + 1, a + n + 1);
rep(i, 1, 2*n) {
int y = a[(i + 1) / 2].r;
int x = i & 1 ? a[(i + 1) / 2].a : a[(i + 1) / 2].b;
X[i] = x, Y[i] = y;
if(!L[y]) L[y] = i;
R[y] = i;
// printf("(%d, %d)\n", x, y);
}
{ //start
db x0 = 0, x2 = (m + 1.0) * v;
if(!inc(x0, 0, x2, m + 1) && leq(x2, s)) {
puts("0");
cerr << "**\n";
return 0;
}
}
rep(i, 1, 2*n) dp[i] = INF;
//pass single point
rep(i, 1, 2*n) {
db x = X[i];
int y = Y[i];
db x2 = x + (m + 1.0 - y) * v;
db x0 = x - (db)y * v;
if(leq(0, x0) && leq(x2, s) && !inc(x0, 0, x2, m + 1)) {
puts("0");
cerr << "()\n";
return 0;
}
}
//pass two points
rep(i, 1, 2*n)
rep(j, i+1, 2*n)
if(X[i] < X[j] && Y[i] < Y[j] && (Y[j] - Y[i]) * v <= (X[j] - X[i])) {
// printf("(%d, %d)!\n", i, j);
db k = (Y[j] - Y[i]) / db(X[j] - X[i]);
db x0 = X[i] - Y[i] / k, x2 = X[j] + (m + 1 - Y[j]) / k;
if(leq(0, x0) && leq(x2, s) && !inc(x0, 0, x2, m + 1)) {
puts("0");
cerr << "[]\n";
return 0;
}
}
ans = INF;
rep(i, 1, 2*n) {
int x = X[i], y = Y[i];
db x0 = x - (db)y * v;
if(leq(0, x0) && !inc(x0, 0, x, y)) {
// printf("x0 = %.1f\n", x0);
dp[i] = 0;
upd(i, v, 0);
} else {
rep(j, 1, i-1) {
if(x > X[j] && y > Y[j] && (y - Y[j]) * v <= (x - X[j])) {
db v0 = (y - Y[j]) / db(x - X[j]);
db x0 = x - (db)y / v0;
if(leq(0, x0) && !inc(x0, 0, x, y)) {
dp[i] = 0;
upd(i, 1 / v0, 0);
break;
}
}
}
}
if(dp[i] == INF) {
rep(j, 1, i-1) {
if(x > X[j] && y > Y[j] && (y - Y[j]) * v <= (x - X[j])) {
if(!inc(X[j], Y[j], x, y)) {
dp[i] = min(dp[i], dp[j] + 1);
DP(i, Y[j], (x - X[j]) / db(y - Y[j]), dp[j] + 1);
}
}
}
}
if(dp[i] < INF) {
db x2 = x + (m + 1 - y) * v;
if(leq(x2, s) && !inc(x, y, x2, m + 1)) {
ans = min(ans, dp[i] + 1);
} else {
rep(j, i+1, 2*n) {
if(x < X[j] && y < Y[j] && (Y[j] - y) * v <= (X[j] - x)) {
db v0 = (Y[j] - y) / db(X[j] - x);
db x2 = x + (db)(m + 1 - y) / v0;
if(leq(x2, s) && !inc(x, y, x2, m + 1)) {
ans = min(ans, dp[i] + 1);
break;
}
}
}
}
}
}
if(ans == INF) ans = -1;
printf("%d\n", ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3704kb
input:
4 3 5 1 1 2 1 3 4 1 2 3 2 3 4 3
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
3 3 12 2 2 10 1 1 6 2 8 12 3
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
8 4 13 2 1 4 1 5 13 1 1 5 2 6 13 2 1 9 3 10 13 3 1 10 4 11 13 4
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
1 1 2 2 1 2 1
output:
-1
result:
ok single line: '-1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
10 7 85 8 76 89 7 22 36 6 17 61 4 62 96 3 57 86 6 51 94 5 39 40 1 31 39 7 7 18 5 67 87 4
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
10 10 91 1 1 100 9 1 100 8 1 100 1 1 100 10 1 100 3 1 100 4 1 100 7 1 100 2 1 100 5 1 100 6
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
10 3 99994 12436 14053 20692 1 20693 72913 1 1 14052 1 36226 100000 3 1 5048 2 1 688 3 70945 100000 2 5049 70944 2 72914 100000 1 689 36225 3
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3368kb
input:
10 7 67853 3238 27043 44174 4 69150 89334 2 65082 73038 1 18887 34795 6 49387 76379 7 63582 76311 4 70393 78225 6 52699 81352 5 79076 90480 6 46727 51948 4
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
10 10 99991 6429 1 100000 6 1 100000 3 1 100000 7 1 100000 5 1 100000 8 1 100000 10 1 100000 4 1 100000 2 1 100000 1 1 100000 9
output:
-1
result:
ok single line: '-1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
100 1 21964 5206 64259 64277 1 11354 11400 1 59905 60165 1 65204 65413 1 56524 57796 1 29791 30173 1 70653 71198 1 93335 93420 1 24188 25637 1 23637 23656 1 92593 92888 1 27676 27903 1 98254 98347 1 25867 26233 1 98617 98915 1 81799 82593 1 65830 65833 1 90917 91368 1 85545 85824 1 12460 12801 1 949...
output:
0
result:
ok single line: '0'
Test #11:
score: -100
Wrong Answer
time: 2ms
memory: 3844kb
input:
100 10 99993 807 44838 54767 6 34286 35646 5 57765 65793 2 28816 31503 6 17001 28771 10 34266 37715 8 1 701 3 96466 96997 2 72476 96463 10 17723 31765 4 36014 80395 4 81278 100000 9 35980 50283 2 81069 90828 8 21774 51612 7 49735 52230 9 61622 83904 6 38580 44837 6 52288 85556 1 90564 95262 7 12874 ...
output:
9
result:
wrong answer 1st lines differ - expected: '6', found: '9'