Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include<vector>
- #define DN 46345
- #define pb push_back
- #define x first
- #define y second
- #include<queue>
- using namespace std;
- ifstream fin("horse.in");
- ofstream fout("horse.out");
- int n,p,l,c,t,k,prl,prc,pr,a[DN];
- int main()
- {
- fin>>n>>p;
- l=c=1;
- pr=p;
- if(p==n*n)
- {
- fout<<n/2+n%2<<' '<<n/2+n%2;
- return 0;
- }
- while(1)
- {
- if(4*n-4+4*(n-2)-4>=p)
- break;
- k+=2;
- p-=4*n-4+4*(n-2)-4;
- n-=4;
- }
- t=4*n-4+4*(n-2)-4;
- p--;
- while(p)
- {
- while(p&&c<n-1)
- {
- p--;
- c+=2;
- if(l==1)
- l=2;
- else
- l=1;
- }
- while(p&&l<n-1)
- {
- p--;
- l+=2;
- if(c==n)
- c=n-1;
- else
- c=n;
- }
- while(p&&c>2)
- {
- p--;
- c-=2;
- if(l==n)
- l=n-1;
- else
- l=n;
- }
- while(p&&l>2)
- {
- p--;
- l-=2;
- if(c==1)
- c=2;
- else
- c=1;
- }
- if(pr!=1&&l==1&&c==1)
- c=3;
- }
- cout<<n<<' '<<k;
- l+=k;
- c+=k;
- fout<<l<<' '<<c<<'\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment