#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){
cout<<"0\n";
return 0;
}
if(cur_d>d || ((d-cur_d)%2)!=0 || cur_d==1){
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
towerdefense.cpp: In function 'int32_t main()':
towerdefense.cpp:86: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 |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Incorrect |
5 ms |
384 KB |
Expected but did not find "impossible". |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
4 ms |
384 KB |
Output is correct |
35 |
Correct |
4 ms |
384 KB |
Output is correct |
36 |
Incorrect |
5 ms |
384 KB |
Expected but did not find "impossible". |
37 |
Halted |
0 ms |
0 KB |
- |