QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571951#6394. Turn on the Lightzfasion#WA 1ms3640kbC++141.4kb2024-09-18 10:35:252024-09-18 10:35:25

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 10:35:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2024-09-18 10:35:25]
  • 提交

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;
			cout << "! " << ans << endl;
			return 0;
		}
		int d1=d;
		d = ask(l);
		if(d==d1)
		{
			cout<<"! "<<l<<endl;
			exit(0);
		}
		if (d == pre + 2)
		{
			l = mid + 1;
		}
		else
		{
			r = mid - 1, l++;
		}
		pre = d;
	}
	cout << "! " << l << endl;
	return false;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

input:

3
1
2

output:

? 2
? 1
! 3

result:

ok Correct position at 3

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3552kb

input:

10
1
2
3
4
5
5

output:

? 5
? 1
? 8
? 6
? 9
? 9
! 9

result:

wrong answer Wrong favorite light!