fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. int n,m;
  11. cin>>n>>m;
  12.  
  13. int i,j;
  14. int ans=0;
  15. int maxd, mind;
  16. if(n>=m) {
  17. maxd = n;
  18. mind = m;
  19. }
  20. else {
  21. maxd = m;
  22. mind = n;
  23. }
  24. n=maxd;
  25. m=mind;//This is to make sure N>M for all cases.
  26. int arr[n][m]={0};
  27.  
  28. for(i=0;i<n;i++) //The explanation is given above.
  29. {
  30. for(j=0;j<m;j++)
  31. {
  32. cout<<"I and J are "<<arr[i][j]<<endl;//Critical Line 2.
  33. if(arr[i][j]==0)
  34. {
  35. ans++;
  36. arr[i][j]=1;
  37. if(i<n-2 && j>0)
  38. arr[i+2][j-1]=1;
  39. if(i<n-2 && j<m-1)
  40. arr[i+2][j+1]=1;
  41. }
  42. }
  43. }
  44. cout<<ans<<endl;
  45. }
  46. return 0;
  47. }
Success #stdin #stdout 0s 16064KB
stdin
1
2 2
stdout
I and J are 0
I and J are 32766
I and J are 0
I and J are 0
3