Advertisement
Zeinab_Hamdy

Untitled

Jul 15th, 2024
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define nl "\n"
  4. #define fi first
  5. #define se second
  6. #define pb push_back
  7. #define ll long long
  8. #define RV return void
  9. #define sz(x) int(x.size())
  10. #define all(v) v.begin(), v.end()
  11. #define rall(v) v.rbegin(), v.rend()
  12. #define fixed(n) fixed << setprecision(n)
  13. #define cin(v) for(auto&x:v) cin >> x;
  14. #define cout(v) for(auto&x:v) cout << x << " ";
  15. void files(){
  16.     #ifndef ONLINE_JUDGE
  17.        freopen("input.txt", "r", stdin);
  18.        freopen("output.txt", "w", stdout);
  19.     #endif
  20. }
  21. //
  22.  
  23. int n  , sum=0;
  24. vector < int > v;
  25. vector < vector < vector < int > > > dp;
  26.  
  27. int rec(int l , int r , int xr , bool turn){
  28.     if(l > r or l > n-1 or r < 0){
  29.         if(xr > (sum ^ xr)) return 1;
  30.         else if((sum ^ xr) > xr) return 0;
  31.         else return -1;
  32.     }
  33.     int & ret=dp[l][r][xr];
  34.     if(~ret)
  35.         return ret;
  36.     if(!turn){
  37.  
  38.         ret =-1e9;
  39.         ret = max(ret , rec(l+1 ,r , xr ^ (v[l]), 1-turn));
  40.         ret = max(ret , rec(l ,r -1, xr ^ (v[r]), 1-turn));
  41.     }else{
  42.         ret = 1e9;
  43.         ret = min(ret , rec(l+1 ,r , xr , 1-turn));
  44.         ret = min(ret , rec(l ,r -1, xr , 1-turn));
  45.     }
  46.  
  47.     return ret;
  48. }
  49.  
  50. void solve(){
  51.  
  52.     cin >> n ;
  53.     v.assign(n,0);
  54.     int mx =0;
  55.     for(int i=0 ; i <n ; i++){
  56.  
  57.         cin >> v[i];
  58.         sum ^= v[i];
  59.        
  60.     }
  61.  
  62.  
  63.     // cout << rec(0 , n-1 , 0 , 0) << nl;
  64.     dp.assign(n+1 , vector < vector <int> > (n+1 , vector < int > (1025 , -1)));
  65.     int ret = rec(0 , n-1 , 0 , 0) ;
  66.     if(ret == 1)
  67.         cout <<"Toty";
  68.     else if(ret ==0)
  69.         cout<<"Boty";
  70.     else
  71.         cout <<"Toty-Boty";
  72.    
  73.    
  74. }      
  75.  
  76.  
  77.  
  78. int main(){
  79.     ios_base::sync_with_stdio(false);
  80.     cin.tie(nullptr);
  81.     cout.tie(nullptr);  
  82.     //  files();
  83.  
  84.     int testCase=1;
  85.         // cin >> testCase ;
  86.     for(int i=1 ; i <= testCase ; i++){
  87.         // cout << "Case "<< i <<": " << nl;
  88.         solve();
  89.     }
  90.  
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement