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;
#define mp make_pair
#define pii pair<int,int>
pii p1,p2,d1,d2;
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int xs,ys,xe,ye,d,cur_d;
cin>>xs>>ys>>xe>>ye>>d;
cur_d=abs(xs-xe)+abs(ys-ye);
if(cur_d>d || ((d-cur_d)%2)!=0){
cout<<"impossible\n";
return 0;
}
if(cur_d<d && xs==xe && ys==ye){//start spot same as end spot...
cout<<"impossible\n";
return 0;
}
p1.first=xe;p1.second=ye;
if(xs<xe)p1.first--;
else if(xs>xe)p1.first++;
if(ys<ye)p1.second--;
else if(ys>ye)p1.second++;
p2=p1;
d1=d2=mp(0,0);
if(xs<xe){
if(ys==ye){
d1.second=-1;
d2.second=1;
}else if(ys<ye){
d1=mp(1,0);
d2=mp(0,1);
}else{
d1=mp(1,0);
d2=mp(0,-1);
}
}else if(xs==xe){
d1=mp(1,0);
d2=mp(-1,0);
}else{
if(ys==ye){
d1.second=-1;
d2.second=1;
}else if(ys<ye){
d1=mp(-1,0);
d2=mp(0,1);
}else{
d1=mp(-1,0);
d2=mp(0,-1);
}
}
if(xs!=xe && ys!=ye){
p1.first+=d1.first;
p1.second+=d1.second;
p2.first+=d2.first;
p2.second+=d2.second;
}
vector<pii> turrets;
while(cur_d<d){
if(turrets.size()>10000){
cout<<"impossible\n";
return 0;
}
turrets.push_back(p1);
if(p1!=p2)turrets.push_back(p2);
p1.first+=d1.first;
p1.second+=d1.second;
p2.first+=d2.first;
p2.second+=d2.second;
cur_d+=2;
}
if(turrets.size()>10000){
cout<<"impossible\n";
return 0;
}
cout<<turrets.size()<<'\n';
for(int i=0;i<turrets.size();i++){
cout<<turrets[i].first<<' '<<turrets[i].second<<'\n';
}
return 0;
}
Compilation message (stderr)
towerdefense.cpp: In function 'int32_t main()':
towerdefense.cpp:82:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<turrets.size();i++){
~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |