# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
216892 | jzh | Tower Defense (CEOI19_towerdefense) | C++14 | 5 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll sx,sy,ex,ey,i,i1,d,x1,y1,x2,y2,a,b;
cin>>sx>>sy>>ex>>ey>>d;
vector<pair<ll,ll> >v;
if (sy>ey||(sy==ey&&sx>ex)){
swap(sy,ey);
swap(sx,ex);
}
d-=abs(sy-ey)+abs(sx-ex);
if (d==0){
cout<<"0\n";
return 0;
}
else if (d<0){
cout<<"impossible\n";
return 0;
}
if (sy+1==ey&&sx+1==ex){
/*
E.
.H
*/
if (d<4||d%2==1){
cout<<"impossible\n";
return 0;
}
d-=4;
x1=sx+1;
y1=sy;
v.push_back({x1,y1});
x2=sx;
y2=sy+1;
v.push_back({x2,y2});
d/=2;
while (d--){
y1--;
x2--;
v.push_back({x1,y1});
v.push_back({x2,y2});
}
}
else if (sy+1==ey&&sx-1==ex){
/*
.E
H.
*/
if (d<4||d%2==1){
cout<<"impossible\n";
return 0;
}
d-=4;
x1=sx-1;
y1=sy;
v.push_back({x1,y1});
x2=sx;
y2=sy+1;
v.push_back({x2,y2});
d/=2;
while (d--){
y1--;
x2++;
v.push_back({x1,y1});
v.push_back({x2,y2});
}
}
else if (sx==ex){//vertical line
//Assume d>0
if (d<2||d%2==1){
cout<<"impossible\n";
return 0;
}
v.push_back({sx,sy+1});
d-=2;
x1=sx;
y1=sy+1;
x2=sx;
y2=sy+1;
d/=2;
while (d--){
x1++;
x2--;
v.push_back({x1,y1});
v.push_back({x2,y2});
}
}
else if (sy==ey){//horizontal line
//Assume d>0
if (d<2||d%2==1){
cout<<"impossible\n";
return 0;
}
v.push_back({sx+1,sy});
d-=2;
x1=sx+1;
y1=sy;
x2=sx+1;
y2=sy;
d/=2;
while (d--){
y1++;
y2--;
v.push_back({x1,y1});
v.push_back({x2,y2});
}
}
else if (ex>sx){
/*
E.
..
.H
*/
if (ex-sx==1||ey-sy==1)d-=2;
else d-=4;
if (d<0||d%2==1){
cout<<"impossible\n";
return 0;
}
d/=2;
v.push_back({sx+1,sy});
v.push_back({sx,sy+1});
x1=sx;
y1=sy+1;
x2=sx+1;
y2=sy;
if (d!=0){
if (ex-sx==1){
v.push_back({sx-1,sy+1});
d--;
x1=sx-1;
}
if (ey-sy==1){
y2=sy-1;
d--;
v.push_back({sx+1,sy-1});
}
}
while (d--){
x1--;
y2--;
v.push_back({x1,y1});
v.push_back({x2,y2});
}
}
else if (sx>ex){
/*
.E
..
H.
*/
if (sx-ex==1||ey-sy==1)d-=2;
else d-=4;
if (d<0||d%2==1){
cout<<"impossible\n";
return 0;
}
d/=2;
v.push_back({sx-1,sy});
v.push_back({sx,sy+1});
x1=sx;
y1=sy+1;
x2=sx-1;
y2=sy;
if (d!=0){
if (sx-ex==1){
v.push_back({sx+1,sy+1});
x1=sx+1;
d--;
}
if (ey-sy==1){
y2=sy-1;
d--;
v.push_back({sx-1,sy-1});
}
}
while (d--){
x1++;
y2--;
v.push_back({x1,y1});
v.push_back({x2,y2});
}
}
else cout<<"Error\n";
cout<<v.size()<<'\n';
for (i=0;i<v.size();i++){
cout<<v[i].first<<' '<<v[i].second<<'\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |