QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883430#9734. Identify Chordlzc0115WA 0ms3456kbC++141.3kb2025-02-05 16:19:552025-02-05 16:19:58

Judging History

This is the latest submission verdict.

  • [2025-02-05 16:19:58]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3456kb
  • [2025-02-05 16:19:55]
  • Submitted

answer

#include<iostream>
#include<algorithm>

using namespace std;

int t, n, w;

int Ask(int x, int y){
  int ans;
  cout << "? " << x + 1 << " " << y + 1 << endl;
  cin >> ans;
  return ans;
}

void Ans(int x, int y){
  int ans;
  cout << "! " << x + 1 << " " << y + 1 << endl;
  cin >> ans;
  if(ans == -1) exit(0);
}

int main(){
  cin >> t;
  while(t--){
    cin >> n;
    int x = 0, y = (n + 1) / 2, d = 0, p;
    w = Ask(x, y);
    while(w == n / 2){
      if(!(n & 1)) x++, y++;
      else if(y - x == (n + 1) / 2) x++;
      else y++;
      w = Ask(x, y);
    }
    int a = Ask((x + 1) % n, y), b = Ask((x + n - 1) % n, y);
    if(a >= w && b >= w) d = n / 2 - (x - 1), p = x;
    else if(a < w){
      int l = 1, r = n / 2;
      while(l <= r){
        int mid = (l + r) >> 1;
        if(Ask((x + mid) % n, y) == w - mid) l = mid + 1;
        else r = mid - 1;
      }
      p = (x + l - 1) % n, d = n / 2 - w + l;
    } else if(b < w){
      int l = 1, r = n / 2;
      while(l <= r){
        int mid = (l + r) >> 1;
        if(Ask((x + n - mid) % n, y) == w - mid) l = mid + 1;
        else r = mid - 1;
      }
      p = (x + n - l + 1) % n, d = n / 2 - w + l;
    }
    if(Ask(p, (p + d) % n) == 1) Ans(p, (p + d) % n);
    else Ans(p, (p + n - d) % n);
  }
  return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3456kb

input:

2
6
2
1
2
1
1
2
-1

output:

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

result:

wrong answer Wrong answer n=6, actual=2-4, guessed=2-5 (test case 1)