QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876776#8058. Binary vs TernaryFangYifanWA 1ms3712kbC++201.6kb2025-01-31 12:53:082025-01-31 12:53:09

Judging History

This is the latest submission verdict.

  • [2025-01-31 12:53:09]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3712kb
  • [2025-01-31 12:53:08]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
constexpr int mod = 998244353;
constexpr int N = 1e6 + 10;

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    if (n == 1) {
        cout << (s == t ? 0 : -1) << "\n";
        return;
    }
    s = "." + s; t = "." + t;
    vector<pair<int, int>> ans;
    auto trans_11_to_10 = [&](int x) {
        ans.push_back({x, x + 1});
        ans.push_back({x + 1, x + 2});
    };
    auto trans_10_to_11 = [&](int x) {
        ans.push_back({x, x + 1});
    };
    auto trans_000_to_0 = [&](int l, int r) {
        ans.push_back({l, r});
    };
    auto trans_11_to_111 = [&](int x) {
        ans.push_back({x, x + 1});
        ans.push_back({x, x + 1});
        ans.push_back({x + 1, x + 2});
    };
    for (int i = 1; i <= n - 1; i++) {
        if (s[i + 1] == '0') trans_10_to_11(i);
    }
    for (int i = n - 1; i >= 1; i--) trans_11_to_10(i);
    trans_000_to_0(2, n);
    trans_10_to_11(1);
    for (int i = 1; i <= m - 2; i++) trans_11_to_111(i);
    for (int i = 1; i <= m; i++) {
        if (t[i] == '0' && (i == m || t[i + 1] == '1')) {
            trans_11_to_10(i - 1);
        }
    }
    for (int i = m - 1; i >= 1; i--) {
        if (t[i] == '0' && t[i + 1] == '0') {
            trans_11_to_10(i - 1);
        }
    }
    cout << ans.size() << "\n";
    for (auto [l, r] : ans) cout << l << ' ' << r << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

3
1
111
110110
1101010
1111
111111

output:

-1
35
2 3
5 6
5 6
6 7
4 5
5 6
3 4
4 5
2 3
3 4
1 2
2 3
2 6
1 2
1 2
1 2
2 3
2 3
2 3
3 4
3 4
3 4
4 5
4 5
4 5
5 6
5 6
5 6
6 7
2 3
3 4
4 5
5 6
6 7
7 8
20
3 4
4 5
2 3
3 4
1 2
2 3
2 4
1 2
1 2
1 2
2 3
2 3
2 3
3 4
3 4
3 4
4 5
4 5
4 5
5 6

result:

ok Haitang Suki (3 test cases)

Test #2:

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

input:

1000
11100
111
1
11110
10001
10
1011
1111
10
1110
1100
11
11010
11
110
11
1
10001
10110
10
10
11111
10000
1001
10
1
11
10111
11
10
1
100
11
10100
1
10
101
11
1100
110
11
1110
1
1001
1
11111
10
10010
10
11001
110
1010
10011
1110
10100
1001
1001
101
100
1
1001
11
101
11
101
1001
1
1
1011
1
10
10
1011
...

output:

15
3 4
4 5
4 5
5 6
3 4
4 5
2 3
3 4
1 2
2 3
2 5
1 2
1 2
1 2
2 3
-1
15
1 2
2 3
3 4
4 5
5 6
3 4
4 5
2 3
3 4
1 2
2 3
2 5
1 2
1 2
2 3
15
1 2
3 4
4 5
2 3
3 4
1 2
2 3
2 4
1 2
1 2
1 2
2 3
2 3
2 3
3 4
13
1 2
1 2
2 3
2 2
1 2
1 2
1 2
2 3
2 3
2 3
3 4
3 4
4 5
10
2 3
3 4
3 4
4 5
2 3
3 4
1 2
2 3
2 4
1 2
12
2 3
4 5...

result:

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