Guest User

Untitled

a guest
Apr 19th, 2020
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.    
  4. #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  5. #include <ext/pb_ds/assoc_container.hpp>
  6. #include <ext/pb_ds/tree_policy.hpp>
  7. using namespace __gnu_pbds;
  8. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  9.    
  10. #define int long long
  11. #define double long double
  12.    
  13. #define all(a)      (a).begin(),(a).end()
  14. #define sz(x)       (int)x.size()
  15.    
  16. #define ff first
  17. #define ss second
  18. #define mp make_pair
  19.          
  20. #define pb push_back
  21. #define endl "\n"
  22.          
  23. #define f(i,l,r) for(int i=l;i<=r;i++)
  24. #define rf(i,r,l) for(int i=r;i>=l;i--)    
  25.  
  26. #define bp __builtin_popcountll
  27. #define inf 3e15
  28.    
  29. const int N=1e5+5;
  30. const int M=1e9+7;
  31.  
  32. void solve()
  33. {
  34.     int x,y;
  35.     cin>>x>>y;
  36.     int p=abs(x-0);
  37.     int q=abs(y-0);
  38.     p=p%2;
  39.     q=q%2;
  40.     if(p==q)
  41.     {
  42.         cout<<"IMPOSSIBLE"<<endl;
  43.         return;
  44.     }
  45.     p=abs(x-0);
  46.     q=abs(y-0);
  47.    
  48.     int sum=0,id=-1;
  49.     for(int i=1;;i*=2)
  50.     {
  51.         sum+=i;
  52.         int oo=sum-p-q;
  53.         oo/=2;
  54.         if((sum-p-q)>=0)
  55.         {
  56.             id=sum;
  57.             break;
  58.         }
  59.     }
  60.     if(sum==p+q)
  61.     {
  62.         for(int i=1;i<=sum;i*=2)
  63.         {
  64.             if(p&i)
  65.             {
  66.                 if(x<0)
  67.                 cout<<"W";
  68.                 else
  69.                 cout<<"E";
  70.             }
  71.             else
  72.             {
  73.                 if(y<0)
  74.                 cout<<"S";
  75.                 else
  76.                 cout<<"N";
  77.             }
  78.         }
  79.         cout<<endl;
  80.         return;
  81.     }
  82.     else
  83.     {
  84.         int tt=sum-p-q;
  85.         tt/=2;
  86.         int f1=0,f2=0;
  87.         for(int i=0;i<=tt;i++)
  88.         {
  89.             if(((p+i)^(q+tt-i)^i^(tt-i))==sum)
  90.             {
  91.                 f1=i;
  92.                 f2=tt-i;
  93.                 break;
  94.             }
  95.         }
  96.         string ans="";
  97.         p+=f1;
  98.         q+=f2;
  99.                 int cnt=0;
  100.             for(int i=1;i<=sum;i*=2)
  101.             {
  102.                 cnt++;
  103.                 if(p&i)
  104.                 {
  105.                     if(x<0)
  106.                     ans+='W';
  107.                     else
  108.                     ans+='E';
  109.                 }
  110.                 else if(q&i)
  111.                 {
  112.                     if(y<0)
  113.                     ans+='S';
  114.                     else
  115.                     ans+='N';
  116.                 }
  117.                 else if(f1&i)
  118.                 {
  119.                     if(x<0)
  120.                     ans+='E';
  121.                     else
  122.                     ans+='W';
  123.                 }
  124.                 else
  125.                 {
  126.                     if(y<0)
  127.                     ans+='N';
  128.                     else
  129.                     ans+='S';
  130.                 }
  131.                
  132.             }
  133.             cout<<ans<<endl;
  134.             return;
  135.     }
  136. }
  137. signed main()  
  138. {
  139.     FAST
  140.     int t=1;
  141.     cin>>t;
  142.     for(int tc=1;tc<=t;tc++)
  143.     {
  144.         cout<<"Case #"<<tc<<": ";
  145.         solve();
  146.     }
  147. }
Add Comment
Please, Sign In to add comment