QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346798#8058. Binary vs Ternaryberarchegas#WA 0ms3652kbC++202.6kb2024-03-08 23:50:372024-03-08 23:50:37

Judging History

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

  • [2024-03-08 23:50:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2024-03-08 23:50:37]
  • 提交

answer

#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
 
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
    
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
const ll INF = 2e18;

string a, b;

void modify(int ini, int fim, string nova) {
    a = a.substr(0, ini) + nova + a.substr(fim + 1, (int)a.size() - fim - 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        cin >> a >> b;
        if (a == b) cout << "0\n";
        else if (a.size() == 1 || b.size() == 1) cout << "-1\n";
        else {
            vector<pii> ops;

            // tirar todos os 0s
            for (int i = 0; i < (int)a.size(); i++) {
                if (a[i] == '0') {
                    int x = i;
                    while (x + 1 < a.size() && a[x + 1] == '0') x++;
                    ops.push_back({i + 1, x + 1});
                    modify(i, x, "0");
                    ops.push_back({i, i + 1});
                    modify(i - 1, i, "11");
                }
            }

            // deixar a com o tamanho de b
            while ((int)a.size() > (int)b.size()) {
                int tam = a.size();
                ops.push_back({tam - 1, tam});
                ops.push_back({tam, tam + 1});
                ops.push_back({tam - 2, tam - 1});
                ops.push_back({tam - 1, tam + 1});
                ops.push_back({tam - 2, tam - 1});
                a.pop_back();
            }
            while ((int)a.size() < (int)b.size()) {
                int tam = a.size();
                ops.push_back({tam - 1, tam});
                ops.push_back({tam - 1, tam + 1});
                ops.push_back({tam - 1, tam + 1});
                ops.push_back({tam, tam + 1});
                a += '1';
            }

            // colocar os 0's que precisamos
            for (int i = 0; i < (int)b.size(); i++) {
                if (b[i] == '0') {
                    int x = i;
                    while (x + 1 < b.size() && b[x + 1] == '0') x++;
                    for (int j = x; j >= i; j--) {
                        ops.push_back({j, j + 1});
                        modify(j - 1, j, "100");
                        ops.push_back({j + 1, j + 2});
                        modify(j, j + 1, "0");
                    }
                    i = x;
                }
            }

            cout << ops.size() << '\n';
            for (pii x : ops) cout << x.first << ' ' << x.second << '\n';
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
111
110110
1101010
1111
111111

output:

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

result:

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