QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883474#9734. Identify Chordlzc0115WA 0ms3584kbC++141.3kb2025-02-05 16:34:222025-02-05 16:34:22

Judging History

This is the latest submission verdict.

  • [2025-02-05 16:34:22]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2025-02-05 16:34:22]
  • 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 / 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;
    }
    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: 3584kb

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: 3584kb

input:

1000
15
5
4
6
1
1
2
1
1
19
5
4
6
4
3
4
5
-1

output:

? 1 8
? 2 8
? 15 8
? 5 8
? 7 8
? 6 8
? 5 8
! 5 8
? 1 10
? 2 10
? 19 10
? 6 10
? 3 10
? 4 10
? 3 8
! 3 17

result:

wrong answer Wrong answer n=19, actual=3-12, guessed=3-17 (test case 2)