Advertisement
Zeinab_Hamdy

Untitled

Apr 20th, 2024
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define nl "\n"
  4. #define cnl cout << nl;
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define ll long long
  9. #define ull unsigned ll
  10. #define RV return void
  11. #define sz(x) int(x.size())
  12. #define all(v) v.begin(), v.end()
  13. #define rall(v) v.rbegin(), v.rend()
  14. #define fixed(n) fixed << setprecision(n)
  15. #define cin(v) for(auto&x:v) cin >> i;
  16. #define cout(v) for(auto&x:v) cout << i << " ";
  17. void files(){
  18.     #ifndef ONLINE_JUDGE
  19.        freopen("input.txt", "r", stdin);
  20.        freopen("output.txt", "w", stdout);
  21.     #endif
  22. }
  23.  
  24.  
  25. void solve( int test ){
  26.  
  27.     int n ;
  28.     cin >> n ;
  29.  
  30.  
  31.  
  32.     bitset < 10 > ans(0);
  33.     int bit=0 , end = log2(n) + (log2(n) !=int(log2(n)));
  34.     set < int > notask;
  35.     while(bit < end){
  36.         int cnt=0 , x , cnt2=0;
  37.         for(int i =0 ; i <= n ; i++){
  38.             bitset < 10 > bitss(i);
  39.             if(bitss[bit])
  40.                 cnt2++;
  41.            
  42.         }
  43.         vector < int > temp;
  44.         for(auto& i : notask){
  45.              bitset < 10 > bitss(i);
  46.             if(bitss[bit])
  47.                 cnt++;
  48.         }
  49.        
  50.         for(int i =1 ; i <= n; i++){
  51.             if(notask.find(i) != notask.end()) continue;
  52.             cout << "? " << i << " " << bit << endl;
  53.             cin >> x;
  54.             if(x){
  55.                cnt++;
  56.                
  57.             }
  58.             else
  59.                 temp.pb(i);
  60.         }
  61.        
  62.         if(cnt < cnt2){
  63.             for(auto& t : temp) notask.insert(t);
  64.             ans[bit]=1;
  65.         }
  66.        
  67.        
  68.        
  69.        
  70.         bit++;
  71.     }
  72.    
  73.     int ret =0 , temp =1;
  74.     for(int i =0 ; i < 10 ; i++) {
  75.         if(ans[i])
  76.             ret += temp;
  77.         temp*=2;
  78.     }
  79.  
  80.     cout << "! " << ret << endl;
  81.  
  82.  
  83.  
  84. }
  85.  
  86.  
  87. int main(){
  88.     // ios_base::sync_with_stdio(false);
  89.     // cin.tie(nullptr);
  90.     // cout.tie(nullptr);
  91.                            
  92.     //  files();
  93.     int testCase=1;
  94.         // cin >> testCase ;
  95.     for(int i=1 ; i <= testCase ; i++){
  96.         solve(i);
  97.     }
  98.  
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement