QOJ.ac

QOJ

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

Judging History

This is the latest submission verdict.

  • [2025-02-05 16:27:40]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3456kb
  • [2025-02-05 16:27:32]
  • 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);
    d = n / 2 - (w - 1);
    if(a >= w && b >= w) 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;
    } 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;
    }
    cerr << w << " " << d << "\n";
    if(Ask(p, (p + d) % n) == 1) Ans(p, (p + d) % n);
    else Ans(p, (p + n - d) % n);
  }
  return 0;
}

详细

Test #1:

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

input:

2
6
2
1
2
1
1
1
1
4
1
1
1
1
1

output:

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

result:

ok ok (2 test cases)

Test #2:

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

input:

1000
15
6
5
6
2
2
3
2
-1

output:

? 1 9
? 2 9
? 15 9
? 5 9
? 7 9
? 6 9
? 5 7
! 5 3

result:

wrong answer Wrong answer n=15, actual=5-8, guessed=5-3 (test case 1)