Submission #539444

#TimeUsernameProblemLanguageResultExecution timeMemory
539444skittles1412Worm Worries (BOI18_worm)C++17
10 / 100
7 ms8400 KiB
#include "bits/extc++.h" using namespace std; template <typename T> void dbgh(const T& t) { cerr << t << endl; } template <typename T, typename... U> void dbgh(const T& t, const U&... u) { cerr << t << " | "; dbgh(u...); } #ifdef DEBUG #define dbg(...) \ cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \ << ": "; \ dbgh(__VA_ARGS__) #else #define cerr \ if (false) \ cerr #define dbg(...) #endif #define endl "\n" #define long int64_t #define sz(x) int((x).size()) namespace s1 { bool solve(int n, int m, int k, int q) { if (m != 1 || k != 1) { return false; } int cache[n]; memset(cache, -1, sizeof(cache)); auto query = [&](int i) -> int { if (!(0 <= i && i < n)) { return -1e9; } if (cache[i] != -1) { return cache[i]; } static int qcnt = 0; qcnt++; assert(qcnt <= q); cout << "? " << i + 1 << " 1 1" << endl; cin >> cache[i]; return cache[i]; }; auto answer = [&](int i) -> void { cout << "! " << i + 1 << " 1 1" << endl; exit(0); }; auto check = [&](int i) -> void { if (query(i) >= max(query(i - 1), query(i + 1))) { dbg(query(i), query(i - 1), query(i + 1)); answer(i); } }; int l = 0, r = n - 1; while ((r - l + 1) > 3) { int madd = (r - l + 1) / 3, m1 = l + madd, m2 = r - madd; dbg(l, r, m1, m2); int a = query(m1), b = query(m2); if (a < b) { l = m1; } else if (a == b) { l = m1; r = m2; } else if (a > b) { r = m2; } } if (l == r) { answer(l); } else if (l + 1 == r) { check(l); answer(r); } else { check(l + 1); check(l); answer(r); } return true; } } void solve() { int n, m, k, q; cin >> n >> m >> k >> q; s1::solve(n, m, k, q); } int main() { ios_base::sync_with_stdio(false); cin.exceptions(ios::failbit); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...