This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 1000
lli n,m,k,q;
pair<lli,lli> res;
lli dir[8] = {-1,0,1,0,0,1,0,-1};
lli arr[MAX+2][MAX+2];
lli query(lli x, lli y) {
cout << "? " << x << ' ' << y << " 1" << endl;
lli a;
cin >> a;
return a;
}
pair<lli,lli> checa(pair<lli,lli> coord) {
lli sector,val = arr[coord.first][coord.second];
pair<lli,lli> nuevo;
rep(i,0,3) {
nuevo = coord;
nuevo.first += dir[i];
nuevo.second += dir[i+4];
if (nuevo.first == 0 || nuevo.first == n+1) continue;
if (nuevo.second == 0 || nuevo.second == m+1) continue;
if (arr[nuevo.first][nuevo.second] == 0) arr[nuevo.first][nuevo.second] = query(nuevo.first, nuevo.second);
if (arr[nuevo.first][nuevo.second] > val) {
val = arr[nuevo.first][nuevo.second];
sector = i;
}
}
if (val == arr[coord.first][coord.second]) return{-1,0};
return {val,sector};
}
pair<lli,lli> binaria(lli ini,lli fin, lli l, lli r, pair<lli,lli> ant, lli num) {
lli mitad,mayor = 0;
pair<lli,lli> coord;
if (ini == fin && r == l) return {ini,r};
lli a,b;
mitad = (ini+fin)/2;
if (num == 1) b = mitad;
else a = mitad;
rep(i,l,r) {
if (num == 1) a = i;
else b = i;
if (arr[a][b] == 0) arr[a][b] = query(a,b);
if (arr[a][b] > mayor) {
mayor = arr[a][b];
coord = {a,b};
}
}
pair<lli,lli> x = checa(coord);
if (x.first == -1) return coord;
lli nuevo = num^1;
if (arr[coord.first][coord.second] >= arr[ant.first][ant.second]) {
if (x.second == 0 || x.second == 3) fin = mitad - 1;
else ini = mitad + 1;
return binaria(l,r,ini,fin,coord,nuevo);
}
else {
if (num == 1) {
if (ant.second > mitad) ini = mitad + 1;
else fin = mitad-1;
}
else {
if (ant.first > mitad) ini = mitad + 1;
else fin = mitad-1;
}
return binaria(l,r,ini,fin,ant,nuevo);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> k >> q;
res = binaria(1,n,1,m,{0,0},0);
cout << "! " << res.first << ' ' << res.second << " 1";
}
Compilation message (stderr)
worm.cpp: In function 'std::pair<long long int, long long int> checa(std::pair<long long int, long long int>)':
worm.cpp:47:23: warning: 'sector' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | return {val,sector};
| ^
worm.cpp: In function 'std::pair<long long int, long long int> binaria(long long int, long long int, long long int, long long int, std::pair<long long int, long long int>, long long int)':
worm.cpp:68:46: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | if (arr[a][b] == 0) arr[a][b] = query(a,b);
| ~~~~~^~~~~
worm.cpp:68:46: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |