QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#498707 | #7674. Skiing | Max_s_xaM | WA | 100ms | 65768kb | C++14 | 6.7kb | 2024-07-30 18:40:57 | 2024-07-30 18:41:00 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 260;
const lf eps = 1e-9;
int n; lf vy, ax;
struct Point
{
lf x, y; int id;
bool operator < (const Point &u) const { return (fabs(y - u.y) < eps ? id < u.id : y < u.y); }
}a[MAXN];
struct Line
{
lf x, y;
bool operator < (const Line &u) const { return x == u.x ? y > u.y : x < u.x; }
};
struct Answer
{
// vector <int> res;
vector <Line> d;
}f[MAXN][MAXN];
vector <Line> mg;
inline lf Calc(lf v1, lf v2, lf t)
{
return (v1 + v2) * t / 2;
}
inline pair <lf, lf> Solve(lf mn, lf mx, lf t, lf dist)
{
lf l = dist - ax * t * t / 2, r = dist + ax * t * t / 2, b, c, delta;
if (Calc(mx + ax * t, mx, t) < dist) return {1e20, -1e20};
if (Calc(mx - ax * t, mx, t) < dist)
{
b = -2 * (ax * t + mx), c = -ax * ax * t * t - 2 * ax * t * mx + mx * mx + 4 * ax * dist;
delta = b * b - 4 * c;
l = max(l, (-b - sqrt(delta)) / 2);
}
if (Calc(mn - ax * t, mn, t) > dist) return {1e20, -1e20};
if (Calc(mn + ax * t, mn, t) > dist)
{
b = 2 * (ax * t - mn), c = -ax * ax * t * t + 2 * ax * t * mn + mn * mn - 4 * ax * dist;
delta = b * b - 4 * c;
r = min(r, (-b + sqrt(delta)) / 2);
}
return make_pair(l, r);
}
int main()
{
// freopen("A.in", "r", stdin);
// freopen("A.out", "w", stdout);
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n), Read(vy), Read(ax);
for (int i = 1, j = 1; i <= n; i++, j++)
{
Read(a[i].x), Read(a[i].y);
if (a[i].y < 0) { i--, n--; continue; }
a[i].y /= vy, a[i].id = j;
}
a[++n] = Point{0, 0, 0};
sort(a + 1, a + n + 1);
if (ax == 0)
{
bool flag = 0;
for (int i = 2; i <= n; i++)
if (a[i].x == 0) { cout << a[i].id << ' '; flag = 1; }
if (!flag) cout << "Cannot visit any targets\n";
return 0;
}
// for (int i = 1; i <= n; i++) cout << a[i].x << ' ' << a[i].y << '\n';
for (int i = 1; i <= n; i++)
{
// f[i][1].res.push_back(a[i].id);
f[i][1].d.push_back(Line{-1e20, 1e20});
}
for (int i = n; i >= 1; i--)
for (int k = 1; k <= n - i + 1; k++)
{
sort(f[i][k].d.begin(), f[i][k].d.end());
lf pl = -1e21, pr = -1e21;
mg.clear();
for (auto [x, y] : f[i][k].d)
{
if (x > pr)
{
if (pl != -1e21) mg.push_back(Line{pl, pr});
pl = x, pr = y;
}
else pr = max(pr, y);
}
if (pl != -1e21) mg.push_back(Line{pl, pr});
f[i][k].d = mg;
// cout << "Solve " << i << ' ' << k << "\n";
// for (auto [x, y] : f[i][k].d) cout << x << ' ' << y << "\n";
// cout << "\n";
for (int j = i - 1; j >= 1; j--)
{
// if (f[j].res.size() > f[i].res.size() + 1 || (f[j].res.size() == f[i].res.size() + 1 && f[j].res[1] < a[i].id)) continue;
lf len = a[i].y - a[j].y, dist = a[i].x - a[j].x;
mg.clear();
for (auto [x, y] : f[i][k].d)
{
auto cur = Solve(x, y, len, dist);
if (cur.first > cur.second) continue;
mg.push_back(Line{cur.first, cur.second});
}
if (mg.size())
{
if (j == 1)
{
bool flag = 0;
for (auto [x, y] : mg)
if ((x < 0 || fabs(x) < eps) && (y > 0 || fabs(y) < eps)) { flag = 1; break; }
if (!flag) continue;
}
// f[j].res = {a[j].id};
// for (auto x : f[i].res) f[j].res.push_back(x);
for (auto x : mg) f[j][k + 1].d.push_back(x);
}
}
}
int x = 1, y = 1;
while (f[1][y].d.size()) y++; y--;
if (y == 1) return cout << "Cannot visit any targets\n", 0;
// cout << "-----------\n";
// cout << x << ' ' << y << "\n";
lf l = 0, r = 0; a[n + 1].id = 2e9;
for (int i = y - 1; i >= 1; i--)
{
int p = n + 1; lf pl = 0, pr = 0;
for (int j = x + 1; j <= n; j++)
{
if (a[j].id > a[p].id || !f[j][i].d.size()) continue;
lf len = a[j].y - a[x].y, dist = a[j].x - a[x].x;
auto cur = Solve(l, r, len, dist);
if (cur.first > cur.second) continue;
for (auto [xx, yy] : f[j][i].d)
if (xx <= cur.second && cur.first <= yy) { pl = cur.first, pr = cur.second, p = j; break; }
}
x = p, l = pl, r = pr;
cout << a[x].id << ' ';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6636kb
input:
4 100 400 -100 100 50 200 -100 300 150 300
output:
1 2 4
result:
ok single line: '1 2 4 '
Test #2:
score: 0
Accepted
time: 1ms
memory: 5224kb
input:
1 100 100 1000 10
output:
Cannot visit any targets
result:
ok single line: 'Cannot visit any targets'
Test #3:
score: 0
Accepted
time: 1ms
memory: 6416kb
input:
0 100 100
output:
Cannot visit any targets
result:
ok single line: 'Cannot visit any targets'
Test #4:
score: 0
Accepted
time: 1ms
memory: 6204kb
input:
2 100 100 100 100 -100 100
output:
Cannot visit any targets
result:
ok single line: 'Cannot visit any targets'
Test #5:
score: 0
Accepted
time: 0ms
memory: 6916kb
input:
2 1000 2001 1000 1000 -1000 1000
output:
1
result:
ok single line: '1 '
Test #6:
score: 0
Accepted
time: 1ms
memory: 6984kb
input:
3 10 30 10 10 -10 10 0 20
output:
1
result:
ok single line: '1 '
Test #7:
score: 0
Accepted
time: 0ms
memory: 6656kb
input:
3 10 31 10 10 -10 10 0 20
output:
1 3
result:
ok single line: '1 3 '
Test #8:
score: 0
Accepted
time: 0ms
memory: 6628kb
input:
4 10 31 10 10 -10 10 0 19 0 20
output:
1 4
result:
ok single line: '1 4 '
Test #9:
score: 0
Accepted
time: 1ms
memory: 5792kb
input:
4 10 31 10 10 -10 10 0 20 0 21
output:
1 3
result:
ok single line: '1 3 '
Test #10:
score: 0
Accepted
time: 1ms
memory: 5824kb
input:
5 10 31 10 10 -10 10 0 19 0 20 0 21
output:
3 4 5
result:
ok single line: '3 4 5 '
Test #11:
score: 0
Accepted
time: 1ms
memory: 5304kb
input:
3 10 50 100 40 -100 40 -100 50
output:
2 3
result:
ok single line: '2 3 '
Test #12:
score: 0
Accepted
time: 1ms
memory: 6508kb
input:
7 10 25 -10 10 10 10 10 20 10 30 0 40 -10 20 -10 30
output:
1 6 7 5
result:
ok single line: '1 6 7 5 '
Test #13:
score: 0
Accepted
time: 100ms
memory: 65768kb
input:
250 1 79988 -10000 1 10000 2 -10000 3 10000 4 -10000 5 10000 6 -10000 7 10000 8 -10000 9 10000 10 -10000 11 10000 12 -10000 13 10000 14 -10000 15 10000 16 -10000 17 10000 18 -10000 19 10000 20 -10000 21 10000 22 -10000 23 10000 24 -10000 25 10000 26 -10000 27 10000 28 -10000 29 10000 30 -10000 31 10...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok single line: '1 2 3 4 5 6 7 8 9 10 11 12 13 ...43 244 245 246 247 248 249 250 '
Test #14:
score: 0
Accepted
time: 63ms
memory: 46552kb
input:
250 1 39999 -10000 1 10000 2 -10000 3 10000 4 -10000 5 10000 6 -10000 7 10000 8 -10000 9 10000 10 -10000 11 10000 12 -10000 13 10000 14 -10000 15 10000 16 -10000 17 10000 18 -10000 19 10000 20 -10000 21 10000 22 -10000 23 10000 24 -10000 25 10000 26 -10000 27 10000 28 -10000 29 10000 30 -10000 31 10...
output:
1 3 4 6 7 9 10 12 13 15 16 18 19 21 22 24 25 27 28 30 31 33 34 36 37 39 40 42 43 45 46 48 49 51 52 54 55 57 58 60 61 63 64 66 67 69 70 72 73 75 76 78 79 81 82 84 85 87 88 90 91 93 94 96 97 99 100 102 103 105 106 108 109 111 112 114 115 117 118 120 121 123 124 126 127 129 130 132 133 135 136 138 139 ...
result:
ok single line: '1 3 4 6 7 9 10 12 13 15 16 18 ...40 241 243 244 246 247 249 250 '
Test #15:
score: 0
Accepted
time: 1ms
memory: 6412kb
input:
1 100 100 0 0
output:
1
result:
ok single line: '1 '
Test #16:
score: 0
Accepted
time: 84ms
memory: 52072kb
input:
250 1 40001 -10000 1 10000 2 -10000 3 10000 4 -10000 5 10000 6 -10000 7 10000 8 -10000 9 10000 10 -10000 11 10000 12 -10000 13 10000 14 -10000 15 10000 16 -10000 17 10000 18 -10000 19 10000 20 -10000 21 10000 22 -10000 23 10000 24 -10000 25 10000 26 -10000 27 10000 28 -10000 29 10000 30 -10000 31 10...
output:
1 2 4 5 6 8 9 10 12 13 14 16 17 18 20 21 22 24 25 26 28 29 30 32 33 34 36 37 38 40 41 42 44 45 46 48 49 50 52 53 54 56 57 58 60 61 62 64 65 66 68 69 70 72 73 74 76 77 78 80 81 82 84 85 86 88 89 90 92 93 94 96 97 98 100 101 102 104 105 106 108 109 110 112 113 114 116 117 118 120 121 122 124 125 126 1...
result:
ok single line: '1 2 4 5 6 8 9 10 12 13 14 16 1...41 242 244 245 246 248 249 250 '
Test #17:
score: 0
Accepted
time: 81ms
memory: 52644kb
input:
250 1 60000 -10000 1 10000 2 -10000 3 10000 4 -10000 5 10000 6 -10000 7 10000 8 -10000 9 10000 10 -10000 11 10000 12 -10000 13 10000 14 -10000 15 10000 16 -10000 17 10000 18 -10000 19 10000 20 -10000 21 10000 22 -10000 23 10000 24 -10000 25 10000 26 -10000 27 10000 28 -10000 29 10000 30 -10000 31 10...
output:
1 2 3 5 6 7 8 10 11 12 13 15 16 17 18 20 21 22 23 25 26 27 28 30 31 32 33 35 36 37 38 40 41 42 43 45 46 47 48 50 51 52 53 55 56 57 58 60 61 62 63 65 66 67 68 70 71 72 73 75 76 77 78 80 81 82 83 85 86 87 88 90 91 92 93 95 96 97 98 100 101 102 103 105 106 107 108 110 111 112 113 115 116 117 118 120 12...
result:
ok single line: '1 2 3 5 6 7 8 10 11 12 13 15 1...41 242 243 245 246 247 248 250 '
Test #18:
score: 0
Accepted
time: 78ms
memory: 59096kb
input:
250 1 70000 -10000 1 10000 2 -10000 3 10000 4 -10000 5 10000 6 -10000 7 10000 8 -10000 9 10000 10 -10000 11 10000 12 -10000 13 10000 14 -10000 15 10000 16 -10000 17 10000 18 -10000 19 10000 20 -10000 21 10000 22 -10000 23 10000 24 -10000 25 10000 26 -10000 27 10000 28 -10000 29 10000 30 -10000 31 10...
output:
1 2 3 4 5 6 8 9 10 11 12 13 14 16 17 18 19 20 21 22 24 25 26 27 28 29 30 32 33 34 35 36 37 38 40 41 42 43 44 45 46 48 49 50 51 52 53 54 56 57 58 59 60 61 62 64 65 66 67 68 69 70 72 73 74 75 76 77 78 80 81 82 83 84 85 86 88 89 90 91 92 93 94 96 97 98 99 100 101 102 104 105 106 107 108 109 110 112 113...
result:
ok single line: '1 2 3 4 5 6 8 9 10 11 12 13 14...42 243 244 245 246 248 249 250 '
Test #19:
score: 0
Accepted
time: 97ms
memory: 64624kb
input:
250 1 79700 -10000 1 10000 2 -10000 3 10000 4 -10000 5 10000 6 -10000 7 10000 8 -10000 9 10000 10 -10000 11 10000 12 -10000 13 10000 14 -10000 15 10000 16 -10000 17 10000 18 -10000 19 10000 20 -10000 21 10000 22 -10000 23 10000 24 -10000 25 10000 26 -10000 27 10000 28 -10000 29 10000 30 -10000 31 10...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 101 102 103 104...
result:
ok single line: '1 2 3 4 5 6 7 8 9 10 11 12 13 ...43 244 245 246 247 248 249 250 '
Test #20:
score: 0
Accepted
time: 85ms
memory: 64044kb
input:
250 1 79950 -10000 1 10000 2 -10000 3 10000 4 -10000 5 10000 6 -10000 7 10000 8 -10000 9 10000 10 -10000 11 10000 12 -10000 13 10000 14 -10000 15 10000 16 -10000 17 10000 18 -10000 19 10000 20 -10000 21 10000 22 -10000 23 10000 24 -10000 25 10000 26 -10000 27 10000 28 -10000 29 10000 30 -10000 31 10...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok single line: '1 2 3 4 5 6 7 8 9 10 11 12 13 ...42 243 244 245 246 247 248 250 '
Test #21:
score: 0
Accepted
time: 1ms
memory: 6680kb
input:
1 1000 2001 1000 1000
output:
1
result:
ok single line: '1 '
Test #22:
score: 0
Accepted
time: 1ms
memory: 6740kb
input:
1 100 200 101 100
output:
Cannot visit any targets
result:
ok single line: 'Cannot visit any targets'
Test #23:
score: 0
Accepted
time: 1ms
memory: 6956kb
input:
2 100 200 0 100 182 200
output:
1 2
result:
ok single line: '1 2 '
Test #24:
score: 0
Accepted
time: 1ms
memory: 7264kb
input:
2 100 200 0 100 183 200
output:
1
result:
ok single line: '1 '
Test #25:
score: 0
Accepted
time: 0ms
memory: 6284kb
input:
1 100 0 0 0
output:
1
result:
ok single line: '1 '
Test #26:
score: 0
Accepted
time: 0ms
memory: 6828kb
input:
3 100 200 0 100 0 200 199 300
output:
1 2 3
result:
ok single line: '1 2 3 '
Test #27:
score: 0
Accepted
time: 0ms
memory: 5296kb
input:
3 100 200 0 100 0 200 200 300
output:
1 2
result:
ok single line: '1 2 '
Test #28:
score: 0
Accepted
time: 1ms
memory: 5884kb
input:
1 100 0 0 100
output:
1
result:
ok single line: '1 '
Test #29:
score: 0
Accepted
time: 0ms
memory: 5164kb
input:
1 100 0 1 100
output:
Cannot visit any targets
result:
ok single line: 'Cannot visit any targets'
Test #30:
score: 0
Accepted
time: 0ms
memory: 5216kb
input:
1 100 0 1 0
output:
Cannot visit any targets
result:
ok single line: 'Cannot visit any targets'
Test #31:
score: 0
Accepted
time: 0ms
memory: 6464kb
input:
8 10000 0 0 0 1 0 0 100 0 50 0 0 0 50 0 0 0 100
output:
1 5 7 4 6 3 8
result:
ok single line: '1 5 7 4 6 3 8 '
Test #32:
score: 0
Accepted
time: 1ms
memory: 5120kb
input:
1 1000 10 -490 10000
output:
1
result:
ok single line: '1 '
Test #33:
score: 0
Accepted
time: 0ms
memory: 5852kb
input:
1 1000 10 510 10000
output:
Cannot visit any targets
result:
ok single line: 'Cannot visit any targets'
Test #34:
score: -100
Wrong Answer
time: 2ms
memory: 5396kb
input:
100 1000 100 1204 616 -3002 565 -3362 4992 15 5064 8596 661 9004 8411 3333 4613 -4814 6136 9846 1695 3605 6918 -7412 5034 772 5861 3135 3921 -1916 7612 7266 7091 7270 8707 6574 7262 -5683 1305 -968 5659 3600 7352 1960 9180 -6773 1793 -3857 4676 -1662 925 593 3552 3418 1233 -5548 65 3206 574 -7160 28...
output:
73 2000000000 2000000000 2000000000 2000000000
result:
wrong answer 1st lines differ - expected: '73 34 88 92 96', found: '73 2000000000 2000000000 2000000000 2000000000 '