MATXOR Giving TLE O(m+n) Solution

#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve()
{
   int k,rows,cols;
   cin>>rows>>cols>>k;
   int res=0;
   for(int x=2;x<=(rows+cols);x++)
   {
       int end=rows+cols;
       int ans=0;
       if(x>(rows+1))
       {
           // ans=min(rows,(end-x+1));
           if(rows<=(end-x+1))
               ans=rows;
           else
           {
               ans=end-x+1;
           }
           // cout<<ans<<"\n";
       }
       else
       {
           // ans=min(x-1,cols);
           if((x-1)<=cols)
           {
               ans=x-1;
           }
           else
           {
               ans=cols;
           }
           // cout<<ans<<"\n";
       }
       if(ans%2==1)
       {
           int z=x+k;
           res=res^z;
       }
       // cout<<res<<" \n";
   }
   cout<<res<<"\n";
}
int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr), cout.tie(nullptr);
   int t=1;
   cin>>t;

   while(t--){
       solve();
   }
   return 0;
}

Can anyone tell me why this code is giving tle Matrix Xor Ploblem Codechef Cook OFF PLEASE HELP

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

Actually, I think I can guess: try moving the fastio stuff to before you read from cin, and link to that submission if it still TLEs.

1 Like

thanks bro, After moving fastio before reading cin works fine, I have done this mistake i don’t know how, but we uses fastio to take fastio and I have used after taking Input.

only this small mistake ruined my 2-3 hrs . I will remember fastio forever. Thanks again

2 Likes