# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
596943 |
2022-07-15T09:43:11 Z |
jasmin |
Roads (CEOI20_roads) |
C++14 |
|
20 ms |
1700 KB |
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
using pii=pair<int,int>;
const int inf=1e18;
void subtask2(int n, vector<pair<pair<int,int>, pair<int,int> > >& p, vector<pair<pair<int,int>, pair<int,int> > >& old){
auto compare=[&](int i, int j){
auto a=p[i];
auto b=p[j];
if(a.first<b.first) return true;
else if(a.first>b.first) return false;
else{
if(a.second<b.second) return true;
return false;
}
};
vector<int> sorted(n);
iota(sorted.begin(), sorted.end(), 0);
sort(sorted.begin(), sorted.end(), compare);
pair<int,int> last={-inf, -inf};
for(int i=0; i<n; i++){
auto a=old[sorted[i]].first;
auto b=old[sorted[i]].second;
if(last.first!=-inf){
cout << last.first << " " << last.second << " " << a.first << " " << a.second << "\n";
}
last=b;
}
}
struct point{
int x;
int y;
point(int x=0, int y=0): x(x), y(y){};
};
struct frac{
int n;
int d;
frac(int n=1, int d=1): n(n), d(d){};
frac operator+(const frac& a)const{
int lcm=a.d*d/__gcd(a.d, d);
return frac(n*lcm/d+a.n*lcm/a.d, lcm);
}
frac operator*(const frac& a) const{
return frac(n*a.n, d*a.d);
}
bool operator<(const frac& a) const{
return n*a.d<d*a.n;
}
};
struct seg{
point p1;
point p2;
pii st;
frac li;
seg(){
p1={0, 0};
p2={0, 0};
st={1, 1};
li={1, 1};
}
seg(point point1, point point2){
p1=point1;
p2=point2;
int dx=p2.x-p1.x;
int dy=p2.y-p1.y;
st={p1.y*dx-p1.x*dy, dx};
frac m(-dx, dy);
li=frac(p1.y,1)+m*frac(p1.x, 1);
};
bool operator<(const seg& a) const{
if(li<a.li) return true;
else if(!(a.li<li)){
return p1.x<a.p1.x;
}
return false;
}
};
bool specialsorting(seg a, seg b){
if(a.st.first*b.st.second<a.st.second*b.st.first){
return true;
}
else if(a.st.first*b.st.second==a.st.second*b.st.first){
return a.p1.x<b.p1.x;
}
return false;
}
void subtask3(int n, vector<pair<pii, pii> >& p){
// sortierpunkte finden
vector<seg> s(n);
for(int i=0; i<n; i++){
s[i]=seg(point(p[i].f.f, p[i].f.s), point(p[i].s.f, p[i].s.s));
}
//sortieren
sort(s.begin(), s.end(), specialsorting);
// verbinden
for(int i=1; i<n; i++){
cout << s[i-1].p2.x << " " << s[i-1].p2.y << " " << s[i].p1.x << " " << s[i].p1.y << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<pair<int,int>, pair<int,int> > >p(n);
bool s2=true;
for(int i=0; i<n; i++){
cin >> p[i].first.first >> p[i].first.second;
cin >> p[i].second.first >> p[i].second.second;
if(p[i].first>p[i].second){
swap(p[i].first, p[i].second);
}
if(p[i].first.first!=p[i].second.first) s2=false;
}
subtask2(n, p, p);
return 0;
if(s2){
subtask2(n, p, p);
return 0;
}
subtask3(n, p);
}
# |
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 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
980 KB |
Output is correct |
5 |
Correct |
20 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
968 KB |
Output is correct |
5 |
Correct |
15 ms |
1700 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Failed |
0 ms |
340 KB |
Condition failed: "!Cross(S[*pi], S[*pa])" |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
980 KB |
Output is correct |
5 |
Correct |
15 ms |
1628 KB |
Output is correct |
6 |
Failed |
0 ms |
212 KB |
Condition failed: "!Cross(S[*pi], S[*pa])" |
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 |
212 KB |
Condition failed: "!Cross(S[*pi], S[*pa])" |
2 |
Halted |
0 ms |
0 KB |
- |