QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#312695#4831. Eager Sortingsocpite0 3ms3560kbC++142.7kb2024-01-24 10:48:362024-01-24 10:48:37

Judging History

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

  • [2024-01-24 10:48:37]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:3560kb
  • [2024-01-24 10:48:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int maxn = 105;

int pos[2][maxn];
pair<int, int> tval[maxn];

int swapping(int a, int b)
{
    if (a == b)
        return 0;
    cout << a << ' ' << b << endl;
    int x;
    cin >> x;
    if (x == -1)
        exit(0);
    if (x == 1)
    {
        swap(pos[tval[a].first][tval[a].second], pos[tval[b].first][tval[b].second]);
        swap(tval[a], tval[b]);
    }
    return x;
}

void merge(pair<int, int> bl1, pair<int, int> bl2)
{
    int sz1 = bl1.second - bl1.first + 1, sz2 = bl2.second - bl2.first + 1;
    for (int i = 0; i < sz1; i++)
    {
        pos[0][i] = i + bl1.first;
        tval[i + bl1.first] = {0, i};
    }
    for (int i = 0; i < sz2; i++)
    {
        pos[1][i] = i + bl2.first;
        tval[i + bl2.first] = {1, i};
    }
    int ptr[2] = {0, 0};
    while (ptr[0] < sz1 || ptr[1] < sz2)
    {
        if (ptr[0] == sz1)
        {
            swapping(bl1.first + ptr[0] + ptr[1], pos[1][ptr[1]]);
            ptr[1]++;
        }
        else if (ptr[1] == sz2)
        {
            swapping(bl1.first + ptr[0] + ptr[1], pos[0][ptr[0]]);
            ptr[0]++;
        }
        else
        {
            int pos1 = pos[0][ptr[0]], pos2 = pos[1][ptr[1]];
            int id[2] = {0, 1};
            if (pos1 > pos2)
            {
                swap(pos1, pos2);
                swap(id[0], id[1]);
            }
            int res = swapping(pos1, pos2);
            swapping(bl1.first + ptr[0] + ptr[1], pos1);
            if (res)
                ptr[id[1]]++;
            else
                ptr[id[0]]++;
        }
    }
}

int main()
{
    vector<pair<int, int>> blocks;
    int n;
    cin >> n;
    for (int i = 1; i <= 2000; i++)
    {
        cout << "1 2" << endl;
        int x;
        cin >> x;
        if (x == -1)
            return 0;
    }
    cout << "-1 -1" << endl;
    return 0;
    int l = 1;
    for (int i = 2; i <= n; i++)
    {
        if (swapping(i - 1, i))
        {
            if (i - 2 > 0)
                blocks.push_back({l, i - 2});
            l = i - 1;
        }
    }
    blocks.push_back({l, n - 1});
    while (blocks.size() >= 2)
    {
        vector<pair<int, int>> new_blocks;
        while (blocks.size() > 1)
        {
            auto bl2 = blocks.back();
            blocks.pop_back();
            auto bl1 = blocks.back();
            blocks.pop_back();
            merge(bl1, bl2);
            new_blocks.push_back({bl1.first, bl2.second});
        }
        if (!blocks.empty())
            new_blocks.push_back(blocks.back());
        reverse(new_blocks.begin(), new_blocks.end());
        blocks = new_blocks;
    }
    cout << "-1 -1" << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 3560kb

Interactor to First Run

5
0
0
0
0
0
0
0
0
-1

First Run to Interactor

1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2

Interactor to Second Run

5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

Second Run to Interactor

1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
...

Manager to Checker

WA
array is not sorted!

result:

wrong answer WA