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;
long long x,y,x2,y2,dist,nr,sensx,sensy,val,i;
int main()
{
cin>> x2 >> y2;
cin>> x >> y;
cin>>nr;
dist=abs(x-x2)+abs(y-y2);
if (dist>nr)
{
cout<<"impossible";
return 0;
}
if (dist==nr)
{
cout<<"0";
return 0;
}
if (dist==1)
{
cout<<"impossible";
return 0;
}
if ((nr-dist)%2==1)
{
cout<<"impossible";
return 0;
}
if (x!=x2&&y!=y2)
{
if (x<x2)
{
sensx=-1;
}
else
{
sensx=1;
}
if (y<y2)
{
sensy=-1;
}
else
{
sensy=1;
}
if (dist==2&&nr<dist+4)
{
cout<<"impossible";
return 0;
}
if (dist==2)
{
val=(nr-dist-4)/2+1;
}
else
{
val=(nr-dist)/2;
}
cout<<val*2<<'\n';
for (i=1;i<=val;i++)
{
cout<<x2+sensx*i<<" "<<y2<<'\n';
cout<<x2<<" "<<y2+sensy*i<<'\n';
}
}
else
if (y==y2)
{
if (x<x2)
{
sensx=-1;
}
else
{
sensx=1;
}
val=(nr-dist)/2;
cout<<2*(val-1)+1<<'\n';
cout<<x2+sensx<<" "<<y<<'\n';
for (i=2;i<=val;i++)
{
cout<<x2+sensx<<" "<<y-i+1<<'\n';
cout<<x2+sensx<<" "<<y+i-1<<'\n';
}
}
else
if (x==x2)
{
if (y<y2)
{
sensy=-1;
}
else
{
sensy=1;
}
val=(nr-dist)/2;
cout<<2*(val-1)+1<<'\n';
cout<<x2<<" "<<y+sensy<<'\n';
for (i=2;i<=val;i++)
{
cout<<x2-i+1<<" "<<y+sensy<<'\n';
cout<<x2+i-1<<" "<<y+sensy<<'\n';
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |