QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22703 | #2365. Flight Collision | li0201# | WA | 71ms | 11612kb | C++20 | 2.3kb | 2022-03-10 15:32:59 | 2022-04-30 01:33:19 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b) for (int i = a; i >= b; --i)
#define NEXT(i, r, v) for (int i = h[r], v; v = e[i].v, i; i = e[i].u)
const int INF = 2e9;
inline int Max(const int &a, const int &b) { return a > b ? a : b; }
inline int Min(const int &a, const int &b) { return a > b ? b : a; }
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
using namespace std;
const int N = 1e5 + 7;
int n;
struct jgt {
int x, v, id;
bool operator<(const jgt &a) const { return id < a.id; }
};
set<jgt> s;
typedef set<jgt>::iterator IT;
struct qwq {
double t;
int a, b;
bool operator<(const qwq &x) const { return t > x.t; }
};
priority_queue<qwq> q;
double query(jgt a, jgt b) {
if (a.x > b.x) swap(a, b);
if (b.v >= a.v) return -233;
return 1.0 * (b.x - a.x) / (a.v - b.v);
}
bool vis[N];
void upd(IT it) {
auto p = it;
if (p != s.begin()) {
--p;
double x = query(*p, *it);
if (x > 0) q.push({x, p->id, it->id});
}
p = it;
++p;
if (p != s.end()) {
double x = query(*it, *p);
if (x > 0) q.push({x, it->id, p->id});
}
}
int main() {
n = read();
FOR(i, 1, n) {
int x = read(), v = read();
s.insert({x, v, i});
}
for (auto it = s.begin(); it != s.end(); ++it) {
upd(it);
}
while (!q.empty()) {
qwq r = q.top();
q.pop();
// printf("%d %d %lf\n", r.a, r.b, r.t);
if (vis[r.a] || vis[r.b]) continue;
vis[r.a] = vis[r.b] = 1;
auto p = s.find({0, 0, r.a}), q = s.find({0, 0, r.b});
s.erase(p);
q = s.erase(q);
if (q != s.end()) upd(q);
if (q != s.begin()) --q, upd(q);
}
int sum = 0;
FOR(i, 1, n) {
if (!vis[i]) ++sum;
}
printf("%d\n", sum);
FOR(i, 1, n) {
if (!vis[i]) printf("%d ", i);
}
puts("");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3584kb
input:
1 -4 13
output:
1 1
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 3724kb
input:
5 1 1000000000 2 1000000000 3 -1000000000 4 -1000000000 5 -1000000000
output:
1 5
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
3 -1000000000 1 999999999 0 1000000000 0
output:
1 3
result:
ok 2 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
2 5 4 10 5
output:
2 1 2
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 3ms
memory: 3704kb
input:
9 10 10 20 7 30 5 40 0 42 0 50 -1 60 -2 70 -10 80 -12
output:
1 1
result:
ok 2 lines
Test #6:
score: 0
Accepted
time: 3ms
memory: 3660kb
input:
5 10 0 20 0 30 1 40 0 50 0
output:
3 1 2 5
result:
ok 2 lines
Test #7:
score: 0
Accepted
time: 54ms
memory: 9832kb
input:
98765 0 -48539 1 -48539 2 -48539 3 -48539 4 -48539 5 -48539 6 -48539 7 -48539 8 -48539 9 -48539 10 -48539 11 -48539 12 -48539 13 -48539 14 -48539 15 -48539 16 -48539 17 -48539 18 -48539 19 -48539 20 -48539 21 -48539 22 -48539 23 -48539 24 -48539 25 -48539 26 -48539 27 -48539 28 -48539 29 -48539 30 -...
output:
98765 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 10...
result:
ok 2 lines
Test #8:
score: -100
Wrong Answer
time: 71ms
memory: 11612kb
input:
99999 -999999396 999999395 -999971669 999999396 -999971668 -999999396 -999961260 999999396 -999961259 -999999396 -999907239 999999396 -999907238 -999999396 -999754561 999999396 -999754560 -999999396 -999662011 999999396 -999662010 -999999396 -999651505 999999396 -999651504 -999999396 -999619141 9999...
output:
1 1
result:
wrong answer 2nd lines differ - expected: '99999', found: '1 '