QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#614072#8935. Puzzle: Easy as ScrabbleSy03WA 0ms3616kbC++202.7kb2024-10-05 15:32:272024-10-05 15:32:27

Judging History

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

  • [2024-10-05 15:32:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-10-05 15:32:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
#define endl '\n'
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int maxn = 2e5 + 10;
const int mod = 1000000007;
#define inl inline
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define forall(i, a) for (auto &i : a)

/**
   ____         ___ _____
  / ___| _   _ / _ \___ /
  \___ \| | | | | | ||_ \
   ___) | |_| | |_| |__) |
  |____/ \__, |\___/____/
         |___/
*/
istream &operator>>(istream &in, vector<int> &v)
{
    for (auto &i : v)
        in >> i;
    return in;
}
ostream &operator<<(ostream &out, vector<int> &v)
{
    for (auto &i : v)
        out << i << " ";
    return out;
}
bool _output = 1;

int ans = -1;
bool suc = 0;
int cnt = 0;
int n;
int sum = 0;
int query(int l, int r)
{
    ++cnt;
    assert(cnt <= (int)ceil(1.5L * log2(n)));
    assert(sum <= 3 * n);
    cout << "? " << l << " " << r << endl;
    sum += r - l + 1;
    int x;
    cin >> x;
    return x;
}
int make(int l, int r, int t)
{
    // cout << "Debug  =  " << l << " " << r << " " << t << endl;
    if (suc)
    {
        return ans;
    }
    if (r - l == 0)
    {
        suc = 1;
        return l;
    }
    else if (r - l == 1)
    {
        suc = 1;
        return r + l - t;
    }
    if (t <= (l + r) / 2)
    {
        int mid = (2 * r + l) / 3;
        int s = query(l, mid);
        if (suc)
        {
            return ans;
        }
        if (s == t)
        {
            return make(l, mid, s);
        }
        else
        {
            if (mid + 1 == r)
            {
                suc = 1;
                return mid + 1;
            }
            int x = query(mid + 1, r);
            return make(mid + 1, r, x);
        }
    }
    else
    {
        int mid = (2 * l + r + 2) / 3;
        int s = query(mid, r);
        if (s == t)
        {
            return make(mid, r, s);
        }
        else
        {
            if (l == mid - 1)
            {
                suc = 1;
                return l;
            }
            int x = query(l, mid - 1);
            return make(l, mid - 1, x);
        }
    }
    if (suc)
    {
        return ans;
    }
}

void solve()
{
    cnt = 0;
    suc = 0;
    sum = 0;
    ans = -1;
    cin >> n;

    int t = query(1, n);
    int ans = make(1, n, t);
    // assert(ans != -1);
    cout << "! " << ans << endl;
}
signed main()
{
    int _ = 1;
    if (_output)
        cin >> _;
    while (_--)
        solve();
    return 0;
}

详细

Test #1:

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

input:

5 5
.CBA...
....x..
..x...C
A.....B
B..x..A
C......
.......

output:

? 1 5
? 1 3
? 4 5
! -1
? 1 5
? 3 5
? 4 5
! -1
? 1 5
? 3 5
? 4 5
! -1
? 1 5
? 3 5
? 4 5
! -1
? 1 5
? 3 5
? 4 5
! -1

result:

wrong answer YES or NO expected in answer, but ? found.