QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#776745#8239. Mysterious TreedodolaWA 1ms3592kbC++171.4kb2024-11-23 20:44:442024-11-23 20:44:45

Judging History

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

  • [2024-11-23 20:44:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3592kb
  • [2024-11-23 20:44:44]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

const int maxn = 3e5 + 50;
const ll inf = 0x3f3f3f3f3f3f;
const vector<pll> dxy = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

void solve() {
  ll n;
  cin >> n;

  ll t;
  auto ask = [&](ll p1, ll p2) {
    cout << "? " << p1 << ' ' << p2 << endl;
    cin >> t;
  };
  auto conf = [&](ll x) { cout << "! " << x << endl; };

  bool flag = false;
  ll u = -1, v = -1;
  for (ll i = 1; i + 1 <= n; i += 2) {
    ask(i, i + 1);
    if (t == 1) {
      flag = true;
      u = i, v = i + 1;
      break;
    }
  }

  if (n % 2 == 0 && !flag) {
    conf(1);
    return;
  }

  if (v + 1 <= n) {
    ask(v, v + 1);
    ll t1 = t, t2;
    if (v + 2 <= n) {
      ask(v, v + 2);
    } else {
      ask(u - 1, v);
    }
    t2 = t;
    if (t1 == 1 && t2 == 1) {
      conf(2);
    } else {
      conf(1);
    }
  } else {
    ask(u, u - 1);
    ll t1 = t, t2;
    ask(u - 2, u);
    t2 = t;
    if (t1 == 1 && t2 == 1) {
      conf(2);
    } else {
      conf(1);
    }
  }
}

void init() {}

int main(void) {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  init();
  int _t = 1;
  cin >> _t;
  cin.get();
  while (_t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3592kb

input:

2
4
1
1
0
4
0
1
1
1

output:

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

result:

ok Correct (2 test cases)

Test #2:

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

input:

87
13
0
0
0
0
0
1
1
1
15
0
0
0
0
0
0
1
0
0

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 12 13
? 10 12
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 14 15
? 12 14
! 1

result:

wrong answer Wrong prediction (test case 2)