Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define cnl cout << nl;
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ull unsigned ll
- #define RV return void
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define fixed(n) fixed << setprecision(n)
- #define cin(v) for(auto&x:v) cin >> i;
- #define cout(v) for(auto&x:v) cout << i << " ";
- void files(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- void solve( int test ){
- int n ;
- cin >> n ;
- bitset < 10 > ans(0);
- int bit=0 , end = log2(n) + (log2(n) !=int(log2(n)));
- set < int > notask;
- while(bit < end){
- int cnt=0 , x , cnt2=0;
- for(int i =0 ; i <= n ; i++){
- bitset < 10 > bitss(i);
- if(bitss[bit])
- cnt2++;
- }
- vector < int > temp;
- for(auto& i : notask){
- bitset < 10 > bitss(i);
- if(bitss[bit])
- cnt++;
- }
- for(int i =1 ; i <= n; i++){
- if(notask.find(i) != notask.end()) continue;
- cout << "? " << i << " " << bit << endl;
- cin >> x;
- if(x){
- cnt++;
- }
- else
- temp.pb(i);
- }
- if(cnt < cnt2){
- for(auto& t : temp) notask.insert(t);
- ans[bit]=1;
- }
- bit++;
- }
- int ret =0 , temp =1;
- for(int i =0 ; i < 10 ; i++) {
- if(ans[i])
- ret += temp;
- temp*=2;
- }
- cout << "! " << ret << endl;
- }
- int main(){
- // ios_base::sync_with_stdio(false);
- // cin.tie(nullptr);
- // cout.tie(nullptr);
- // files();
- int testCase=1;
- // cin >> testCase ;
- for(int i=1 ; i <= testCase ; i++){
- solve(i);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement