Submission #216892

#TimeUsernameProblemLanguageResultExecution timeMemory
216892jzhTower Defense (CEOI19_towerdefense)C++14
25 / 100
5 ms512 KiB
#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)

towerdefense.cpp: In function 'int main()':
towerdefense.cpp:196:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v.size();i++){
              ~^~~~~~~~~
towerdefense.cpp:7:22: warning: unused variable 'i1' [-Wunused-variable]
     ll sx,sy,ex,ey,i,i1,d,x1,y1,x2,y2,a,b;
                      ^~
towerdefense.cpp:7:39: warning: unused variable 'a' [-Wunused-variable]
     ll sx,sy,ex,ey,i,i1,d,x1,y1,x2,y2,a,b;
                                       ^
towerdefense.cpp:7:41: warning: unused variable 'b' [-Wunused-variable]
     ll sx,sy,ex,ey,i,i1,d,x1,y1,x2,y2,a,b;
                                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...