Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
- #define int long long
- #define double long double
- #define all(a) (a).begin(),(a).end()
- #define sz(x) (int)x.size()
- #define ff first
- #define ss second
- #define mp make_pair
- #define pb push_back
- #define endl "\n"
- #define f(i,l,r) for(int i=l;i<=r;i++)
- #define rf(i,r,l) for(int i=r;i>=l;i--)
- #define bp __builtin_popcountll
- #define inf 3e15
- const int N=1e5+5;
- const int M=1e9+7;
- void solve()
- {
- int x,y;
- cin>>x>>y;
- int p=abs(x-0);
- int q=abs(y-0);
- p=p%2;
- q=q%2;
- if(p==q)
- {
- cout<<"IMPOSSIBLE"<<endl;
- return;
- }
- p=abs(x-0);
- q=abs(y-0);
- int sum=0,id=-1;
- for(int i=1;;i*=2)
- {
- sum+=i;
- int oo=sum-p-q;
- oo/=2;
- if((sum-p-q)>=0)
- {
- id=sum;
- break;
- }
- }
- if(sum==p+q)
- {
- for(int i=1;i<=sum;i*=2)
- {
- if(p&i)
- {
- if(x<0)
- cout<<"W";
- else
- cout<<"E";
- }
- else
- {
- if(y<0)
- cout<<"S";
- else
- cout<<"N";
- }
- }
- cout<<endl;
- return;
- }
- else
- {
- int tt=sum-p-q;
- tt/=2;
- int f1=0,f2=0;
- for(int i=0;i<=tt;i++)
- {
- if(((p+i)^(q+tt-i)^i^(tt-i))==sum)
- {
- f1=i;
- f2=tt-i;
- break;
- }
- }
- string ans="";
- p+=f1;
- q+=f2;
- int cnt=0;
- for(int i=1;i<=sum;i*=2)
- {
- cnt++;
- if(p&i)
- {
- if(x<0)
- ans+='W';
- else
- ans+='E';
- }
- else if(q&i)
- {
- if(y<0)
- ans+='S';
- else
- ans+='N';
- }
- else if(f1&i)
- {
- if(x<0)
- ans+='E';
- else
- ans+='W';
- }
- else
- {
- if(y<0)
- ans+='N';
- else
- ans+='S';
- }
- }
- cout<<ans<<endl;
- return;
- }
- }
- signed main()
- {
- FAST
- int t=1;
- cin>>t;
- for(int tc=1;tc<=t;tc++)
- {
- cout<<"Case #"<<tc<<": ";
- solve();
- }
- }
Add Comment
Please, Sign In to add comment