QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#588376#8058. Binary vs TernaryXiaoTieWA 0ms3492kbC++172.2kb2024-09-25 10:08:482024-09-25 10:08:50

Judging History

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

  • [2024-09-25 10:08:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3492kb
  • [2024-09-25 10:08:48]
  • 提交

answer

#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#define int long long
#define endl "\n"
#define bit(x) (1LL << x)
#define inf (int)1e18
using namespace std;

typedef pair<int, int> PII;

int p = 0;

void solve()
{
    string A, B;
    cin >> A >> B;
    if (A == "1"  && B != "1") {
        cout << "-1" << endl;
        return;
    }
    B = '?' + B;
    vector<PII> ans;
    queue<int> pos;
    const int m = B.size();
    int cnt1 = 0;
    for (int i = 1; i <= m ; i ++)
        cnt1 += B[i] == '1';
    while (A.size() && A[0] == '0') {
        A.erase(A.begin());
        ans.push_back({1, 1});
    }
    for (int i = 0; i < A.size() ; i ++) {
        if (A[i] == '1')
            cnt1 --;
        if (A[i] == '0') {
            A[i] = '1', ans.push_back({i, i + 1});
            cnt1 --;
        }
    }
    while (cnt1 > 0) {
        ans.push_back({A.size() - 1, A.size()});
        ans.push_back({A.size() - 1, A.size()});
        ans.push_back({A.size(), A.size() + 1});
        cnt1 --;
        A += '1'; 
    }
    while (cnt1 < 0) {
        ans.push_back({A.size() - 1, A.size()});
        ans.push_back({A.size(), A.size() + 1});
        A.pop_back();
        cnt1 ++;
    }
    int cnt = 0;
    for (int i = 1 ; i <= m ; i ++) {
        if (B[i] == '0')
            cnt ++;
        if (B[i] == '1' || i == m) {
            pos.push(cnt);
            cnt = 0;
        }
    }
    int now = 1;
    while (pos.size()) {
        auto t = pos.front();
        pos.pop();
        ans.push_back({now, now + 1});

        if (t == 1) {
            ans.push_back({now + 1, now + 1});
        }
        else {
            for (int j = 1 ; j <= t - 2 ; j ++) {
                ans.push_back({now, now + 1});
                ans.push_back({now, now + 1});
            }
        }
        now += t + 1;
    }
    cout << ans.size() << endl;
    for (auto [x, y] : ans)
        cout << x << " " << y << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
111
110110
1101010
1111
111111

output:

-1
14
2 3
5 6
5 6
6 7
4 5
5 6
1 2
2 3
3 4
4 4
5 6
6 6
7 8
8 8
13
3 4
3 4
4 5
4 5
4 5
5 6
1 2
2 3
3 4
4 5
5 6
6 7
7 8

result:

wrong answer (l,r) is invalid (test case 2)