Advertisement
md_nihal

CodeChef_QHOUSE.cpp

Mar 22nd, 2024 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. // Author : md_nihal
  2.  
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5.  
  6. #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
  7. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
  8. #define Md_Nihal ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  9.  
  10. #include <ext/pb_ds/assoc_container.hpp>
  11. #include <ext/pb_ds/tree_policy.hpp>
  12.  
  13. typedef unsigned long long ull;
  14. #define int long long
  15. #define i_64 int64_t
  16. #define sz(a) (int)a.size()
  17. #define vi vector<int>
  18. #define pii pair<int,int>
  19. #define vpi vector<pii>
  20. #define all(x) x.begin(),x.end()
  21. #define ALL(x) x.rbegin(),x.rend()
  22. #define rep(x,n) for (int i = x; i <x+n; i++)
  23. const int mod = 1e9 + 7, inf = LONG_LONG_MAX, N = 1e6 + 7, MAX = 1e14 + 4;
  24.  
  25. template<class T, class V>istream& operator>>(istream &in, pair<T, V> &a) {in >> a.first >> a.second; return in;}
  26. template<class T>istream& operator>>(istream &in, vector<T> &a) {for (auto &i : a) {in >> i;} return in;}
  27. template<class T, class V>ostream& operator<<(ostream &os, pair<T, V> &a) {os << a.first << " " << a.second; return os;}
  28. template<class T>ostream& operator<<(ostream &os, vector<T> &a) {for (auto &i : a) {os << i << " ";} return os;}
  29.  
  30. /*----------------------------------------------- PBDS --------------------------------------------*/
  31.  
  32. using namespace __gnu_pbds;
  33. template<class T>
  34. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
  35. template<class key, class value, class cmp = less<key>>
  36. using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
  37. // find_by_order(k)  returns iterator to kth element starting from 0;
  38. // order_of_key(k) returns count of elements strictly smaller than k;
  39.  
  40. /*----------------------------------------------- PBDS ends --------------------------------------------*/
  41.  
  42. #ifndef ONLINE_JUDGE
  43. #include "/home/anonymous/Templates/debug.hpp"
  44. #else
  45. #define debug(x...);
  46. #endif
  47.  
  48. /*=========================================== SOLUTION ===========================================*/
  49.  
  50. int query(char cordinate,int val){
  51.     int low=0,high=1000,res=0;
  52.     while(low<=high){
  53.         int mid=low+(high-low)/2;
  54.  
  55.         if(cordinate=='x'){
  56.             cout<<"? "<<mid<<" "<<val<<endl;
  57.         }else cout<<"? "<<val<<" "<<mid<<endl;
  58.  
  59.         string resp; cin>>resp;
  60.         if(resp=="YES"){
  61.             res=mid;
  62.             low=mid+1;
  63.         }else high=mid-1;
  64.  
  65.     }
  66.     return res;
  67. }
  68.  
  69. void __solve() {
  70.  
  71.     int square=0,triangle=0,tri_top=0;
  72.  
  73.     square=2*query('x',0); //leftmost point for square
  74.     triangle=2*query('x',square); //leftmost point for triangle
  75.     tri_top=query('y',0)-square; // topmost point for traingle
  76.     int ans=square*1ll*square + triangle*tri_top/2; //area
  77.     cout<<"! "<<ans;
  78. }
  79.  
  80.  
  81.  
  82. /*============================================= MAIN =============================================*/
  83.  
  84. int32_t  main()
  85. {
  86.     Md_Nihal;
  87.     int testcases = 1;    //cin >> testcases;
  88.     for (int i = 0; i < testcases; i++,__solve(),cout << endl);
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement