# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
574685 |
2022-06-09T08:52:34 Z |
piOOE |
Roads (CEOI20_roads) |
C++17 |
|
29 ms |
3752 KB |
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
#define y1 pi300iq
#define double long double
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const int N = 200000, infI = 1e9 + 7;
const double eps = 1e-9;
int X[N], Y[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<int, int>> yy;
bool ok = true;
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 > x2 || (x1 == x2 && y1 > y2)) {
swap(x1, x2);
swap(y1, y2);
}
X[i << 1] = x1, Y[i << 1] = y1;
X[i << 1 | 1] = x2, Y[i << 1 | 1] = y2;
yy.emplace_back(x1, y1);
yy.emplace_back(x2, y2);
ok &= X[i << 1] == X[i << 1 | 1];
}
sort(all(yy));
auto get_idx = [&yy](int x, int y) {
int it = lower_bound(all(yy), make_pair(x, y)) - begin(yy);
if (it == sz(yy) || yy[it] != make_pair(x, y)) {
return -1;
}
return it;
};
if (ok) {
map<int, vector<pair<int, int>>> mp;
for (int i = 0; i < n; ++i) {
mp[X[i << 1]].emplace_back(Y[i << 1], Y[i << 1 | 1]);
}
pair<int, int> lst = {-infI, -infI};
for (auto [x, a]: mp) {
sort(all(a));
if (lst.first != -infI) {
cout << lst.first << " " << lst.second << " " << x << " " << a[0].first << '\n';
}
lst = {x, a[0].first};
for (int i = 0; i < sz(a) - 1; ++i) {
cout << x << " " << a[i].second << " " << x << " " << a[i + 1].first << '\n';
}
}
} else {
//I assume that every segment is parallel to each other
double K = (Y[0] - Y[1]) / (double) (X[0] - X[1]);
auto cmp = [&K](int i, int j) {
if (X[i << 1] == X[j << 1]) {
return Y[i << 1] < Y[j << 1];
}
double z = (Y[i << 1] - X[i << 1] * K) - (Y[j << 1] - X[j << 1] * K);
if (abs(z) < eps) {
return X[i << 1] < X[j << 1];
} else {
return z >= eps;
}
};
vector<int> ord(n);
iota(all(ord), 0);
sort(all(ord), cmp);
pair<int, int> lst = {-infI, -infI};
for (int i = 0; i < n; ++i) {
int x = ord[i];
if (lst.first != -infI)
cout << lst.first << " " << lst.second << " " << X[x << 1] << " " << Y[x << 1] << '\n';
lst = {X[x << 1 | 1], Y[x << 1 | 1]};
}
}
return 0;
}
Compilation message
roads.cpp: In function 'int main()':
roads.cpp:42:10: warning: variable 'get_idx' set but not used [-Wunused-but-set-variable]
42 | auto get_idx = [&yy](int x, int y) {
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
0 ms |
340 KB |
Condition failed: "!Cross(S[*pi], S[*pa])" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
16 ms |
2008 KB |
Output is correct |
5 |
Correct |
24 ms |
3752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
12 ms |
2056 KB |
Output is correct |
5 |
Correct |
26 ms |
3752 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Failed |
13 ms |
1044 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pa], S[*pf])" |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
13 ms |
2008 KB |
Output is correct |
5 |
Correct |
29 ms |
3668 KB |
Output is correct |
6 |
Failed |
0 ms |
212 KB |
Condition failed: "pf == Sline.end() || !Cross(S[*pa], S[*pf])" |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
0 ms |
212 KB |
Condition failed: "!Cross(S[*pi], S[*pa])" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Failed |
0 ms |
340 KB |
Condition failed: "!Cross(S[*pi], S[*pa])" |
2 |
Halted |
0 ms |
0 KB |
- |