QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678322#8058. Binary vs TernaryTokaiZaopen#WA 0ms3620kbC++202.0kb2024-10-26 14:38:282024-10-26 14:38:29

Judging History

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

  • [2024-10-26 14:38:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2024-10-26 14:38:28]
  • 提交

answer

#include <bits/stdc++.h>

#define int ll
using ll = long long;

// #define MING_LE

using namespace std;

string a, b;

void solve();

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int __ = 1;
    cin >> __;

    while (__--)
        solve();

    return 0;
}

void solve()
{
    cin >> a >> b;
    if (a == "1")
    {
        if (b != "1")
            cout << "-1\n";
        else
            cout << "0\n";
        return;
    }
    if (b == "1" && a.size() > 1)
    {
        cout << "-1\n";
        return;
    }

    vector<pair<int, int>> ans;

    while (a != "10")
    {
#ifdef MING_LE
        cout << a << '\n';
#endif
        int st = -1;
        for (int i = 0; i < (int)a.size() - 1; i++)
        {
            if (a[i] == '1' && a[i + 1] == '1')
            {
                ans.emplace_back(i + 1, i + 2);
                a[i + 1] = '0';
                a.insert(a.begin() + i + 1, '0');
                st = i + 1;
                break;
            }
        }
        if (st < 0)
            break;
        bool flag = 0;
        for (int j = st; j < a.size(); j++)
        {
            if (a[j] == '1')
            {
                flag = 1;
                ans.emplace_back(st + 1, j + 1);
                string buffer = a;
                a = buffer.substr(0, st) + "1";
                if (j + 1 < buffer.size())
                    a = a + buffer.substr(j + 1, buffer.size() - (j + 1));
                break;
            }
        }
        if (!flag)
        {
            ans.emplace_back(st + 1, a.size());
            a = a.substr(0, st) + "0";
        }
    }

    if (a != "10")
        ans.emplace_back(2, a.size());

    if (b != "10")
        ans.emplace_back(1, 2);

    cout << ans.size() << '\n';
    for (auto it : ans)
        cout << it.first << " " << it.second << '\n';
}

/*
3
1
111
110110
1101010
1111
111111
*/

/*
1
110110
1101010
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
111
110110
1101010
1111
111111

output:

-1
7
1 2
2 5
1 2
2 4
1 2
2 4
1 2
7
1 2
2 4
1 2
2 4
1 2
2 3
1 2

result:

wrong answer S!=T after all operations (test case 2)