#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);
}
}
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;
}
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:71:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<turrets.size();i++){
~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 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 |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 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 |
4 ms |
384 KB |
Output is correct |
14 |
Incorrect |
4 ms |
384 KB |
Expected but did not find "impossible". |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 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 |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 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 |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 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 |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Incorrect |
4 ms |
384 KB |
Expected but did not find "impossible". |
22 |
Halted |
0 ms |
0 KB |
- |