QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571925 | #6394. Turn on the Light | zfasion# | WA | 1ms | 3632kb | C++14 | 1.4kb | 2024-09-18 10:23:42 | 2024-09-18 10:23:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e6 + 20, M = 998244353;
#define eps 1e-12
#define int long long
// #define int __int128
#define ll long long
#define all(x) x.begin(), x.end()
// #define endl '\n'
#define ls (p << 1)
#define rs ((p << 1) | 1)
#define f1 first
#define pb push_back
#define f2 second
#define IOS std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0), std::cout << std::fixed << std::setprecision(2);
int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
return x;
}
void write(int x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
signed main()
{
IOS;
int n;
cin >> n;
int l = 1, r = n;
auto ask = [&](int x) -> int
{
cout << "? " << x << endl;
int d;
cin >> d;
return d;
};
int ans = l + r >> 1;
int pre = 0;
while (l < r)
{
int mid = l + r >> 1;
int d = ask(mid);
if (d == pre)
{
ans = mid;
break;
}
if(d==pre-1)
{
r=mid-1;
pre=d;
continue;
}
pre = d;
d = ask(l);
if (d == pre + 1)
{
l = mid + 1;
}
else
{
r = mid - 1;
if (l < r)
l++;
}
pre = d;
ans = l;
}
cout << "! " << ans << endl;
return false;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
3 1 2
output:
? 2 ? 1 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3632kb
input:
10 1 2 3 4 5 5
output:
? 5 ? 1 ? 8 ? 6 ? 9 ? 9 ! 9
result:
wrong answer Wrong favorite light!