1934C - Find a Mine - CodeForces Solution


constructive algorithms interactive

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
#define ff first
#define ss second
#define ld long double
#define ll long long
#define pb push_back
#define INF 1e18
#define ppb pop_back
#define fl(i,n,m) for(int i=n;i<m;i++)
#define pii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define print(a) for(auto &it:a) cout<<it<<" "; cout<<endl
#define mii map<int,int>
#define setbits(x) __builtin_popcountll(x)
#define sz(x) ((int)(x).size())
#define all(a) a.begin(),a.end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
 
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
 
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m
 
int pw(ll int a, ll int b, ll int m) {
    if(b==0) {
        return 1;
    }
 
    if(b%2 == 0) {
        ll int t = pw(a, (b/2), m);
        return (1ll*t*t)%m;
    }
    else {
        ll int t = pw(a, (b-1)/2, m);
        t = (1ll*t*t)%m;
        return (1ll*a*t)%m;
    }
}
 
const int N=500000;
const ll int mod = 1e9 + 7;
 
ll int fact[N], invfact[N];
void init() {
    ll int p = mod;
    fact[0]=1;
    int i;
    for(i=1; i<N; i++) {
        fact[i] = (i*fact[i-1])%p;
    }
    i--;
    invfact[i] = pw(fact[i], p-2, p);
    for(i--; i>=0; i--) {
        invfact[i] = (invfact[i+1]*(i+1))%p;
    }
}
 
int ncr(int n, int r) {
    return (((fact[n]*invfact[r])%mod)*invfact[n-r])%mod;
}
 
vector<int> sieve_of_eratosthenes(int n) {
    vector<int> prm;
    bool is_prime[n + 1];
    memset(is_prime, true, sizeof(is_prime));
    is_prime[0] = is_prime[1] = false;
    for(int p = 2; p * p <= n; p++) {
        if(is_prime[p]) {
            for(int i = p * p; i <= n; i += p) {
                is_prime[i] = false;
            }
        }
    }
    for(int i = 2; i <= n; i++) {
        if(is_prime[i]) {
            prm.pb(i);
        }
    }
    return prm;
}
 
void solve() {
    int n,m;
    cin>>n>>m;
    cout<<"? "<<1<<" "<<1<<endl;
    cout.flush();
    int x;
    cin>>x;
    x += 2;
    int nc = 0,nr=0;
    if(x>m){
        nc = m,nr = x-m;
    }
    else{
        nr = 1,nc = x-1;
    }
    int nr1=0,nc1=0;
    if(x>n){
        nr1 = n,nc1 = x-n;
    }
    else{
        nc1 = 1,nr1 = x-1;
    }
    cout<<"? "<<nr<<" "<<nc<<endl;
    cin>>x;
    nr += x/2;
    nc -= x/2;
    cout<<"? "<<nr1<<" "<<nc1<<endl;
    cin>>x;
    nr1 -= x/2;
    nc1 += x/2;
    cout<<"? "<<nr<<" "<<nc<<endl;
    cin>>x;
    if(x==0){
        cout<<"! "<<nr<<" "<<nc<<endl;
    }
    else{
        cout<<"! "<<nr1<<" "<<nc1<<endl;
    }
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //init();
    int tc=1;
    cin>>tc;
    while(tc--){
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix