QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555655#8939. Permutationalexz1205WA 1ms3796kbC++141007b2024-09-10 07:39:542024-09-10 07:39:54

Judging History

This is the latest submission verdict.

  • [2024-09-10 07:39:54]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3796kb
  • [2024-09-10 07:39:54]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

constexpr double phi = (1+sqrt(5))/2;
constexpr double phiRat = 1/((1+sqrt(5))/2);

int getSecond(int l, int r){
	if (l+1 == r){
		return l;
	}
	printf("? %d %d\n", l+1, r);
	fflush(stdout);
	int ind;
	scanf("%d", &ind);
	return ind-1;
}

int ran(int l, int r, int ind){
	if (l+1 == r){
		return ind;
	}
	if (r-l == 2){
		return l + (ind == l);
	}
	int len = (int)((double)(r-l) * phiRat);
	if (ind >= l + len){
		int res = getSecond(r-len, r);
		if (res == ind){
			return ran(r-len, r, ind);
		}else {
			return ran(l, r-len, getSecond(l, r-len));
		}
	}else {
		int res = getSecond(l, l+len);
		if (res == ind){
			return ran(l, l+len, ind);
		}else {
			return ran(l+len, r, getSecond(l+len, r));
		}
	}
}

void solve(){
	int n;
	scanf("%d", &n);
	printf("! %d\n", 1+ran(0, n, getSecond(0, n)));
	fflush(stdout);
}

int main(){
	int t;
	scanf("%d", &t);
	for (int x = 0; x < t; x ++){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3796kb

input:

3
5
3
2
5
6
6
5
3

output:

? 1 5
? 1 3
? 4 5
! 4
? 1 6
? 4 6
? 1 3
! 3

result:

wrong answer Wrong prediction (test case 2)