이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
template <class T>
using Vec = std::vector<T>;
int N, M, K, Q;
std::map<std::tuple<int, int, int>, int> memo;
int query(const int i, const int j, const int k) {
std::tuple<int, int, int> tup(i, j, k);
const auto itr = memo.find(tup);
if (itr != memo.end()) {
return itr -> second;
}
std::cout << "? " << i << ' ' << j << ' ' << k << std::endl;
int ret;
std::cin >> ret;
assert(ret != -1);
memo.emplace(std::move(tup), ret);
return ret;
}
void answer(const int i, const int j, const int k) {
std::cout << "! " << i << ' ' << j << ' ' << k << std::endl;
std::exit(EXIT_SUCCESS);
}
template <class Select>
int fib_search(const int N, const Select& less) {
Vec<int> fib(2, 1);
while (fib.back() < N + 1) {
const auto tmp = fib[fib.size() - 1] + fib[fib.size() - 1];
fib.push_back(tmp);
}
int l = 0, r = N + 1, k = (int) fib.size() - 1;
while (r - l > 2) {
k -= 1;
const auto m1 = r - fib[k];
const auto m2 = l + fib[k];
if (less(m1, m2)) {
l = m1;
}
else {
r = m2;
}
}
return l + 1;
}
int main() {
std::cin >> N >> M >> K >> Q;
if (M == 1 and K == 1) {
const auto ans = fib_search(N, [&](const int i, const int j) {
if (j > N) return false;
return query(i, 1, 1) <= query(j, 1, 1);
});
answer(ans, 1, 1);
}
return 0;
}
# | 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... |