Submission #212490

#TimeUsernameProblemLanguageResultExecution timeMemory
212490kai824Tower Defense (CEOI19_towerdefense)C++17
100 / 100
5 ms512 KiB
#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<=1){//start spot same as end spot... cout<<"impossible\n"; return 0; }else if(cur_d==2 && xs!=xe && ys!=ye){//diff column, diff row... if(d==4){ 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); if(cur_d==2 && xs!=xe && ys!=ye){//diff column, diff row... cur_d+=4; }else cur_d+=2; p1.first+=d1.first; p1.second+=d1.second; p2.first+=d2.first; p2.second+=d2.second; } 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:92:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<turrets.size();i++){
               ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...