QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#414869#8058. Binary vs Ternarykevinshan#WA 0ms3524kbC++172.3kb2024-05-19 23:11:102024-05-19 23:11:10

Judging History

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

  • [2024-05-19 23:11:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3524kb
  • [2024-05-19 23:11:10]
  • 提交

answer

#pragma GCC optimize("Ofast,O3,unroll-loops")

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

#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cbit(x) __builtin_popcount(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
const int xm[4] = {-1, 1, 0, 0};
const int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const ll POW = 9973;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int t; cin>>t;
    while(t--){
        string a;
        string b;
        cin>>a>>b;
        if(a.size() == 1 && b.size() == 1) {
            cout<<0<<"\n";
        }
        else if(a.size() == 1) {
            cout<<-1<<"\n";
        }
        else if(b.size() == 1) {
            cout<<-1<<"\n";
        }
        else {
            // first reduce a
            int sz = a.size();
            int bk;
            vector<pair<int, int>> mv;
            for(int i=a.size()-1; i>=0; i--){
                if(a[i] == '1') {
                    bk = i;
                    break;
                }
            }
            mv.pb({bk+2, a.size()});
            sz -= sz - 2 - bk;
            for(int j=sz-3; j>=0; j--) {
                if(a[j] == '0') {
                    mv.pb({j+1, j+2});
                }
                else {
                    mv.pb({j+1, j+2});
                    mv.pb({j+2, j+4});
                }
            }
            // string should be 10
            mv.pb({1,2});
            // now string is 11
            int c = 2;
            while(c<b.size()) {
                mv.pb({c-1,c});
                c++;
                mv.pb({c-2, c-1});
                mv.pb({c-1,c});
            }
            for(int i=b.size()-1; i>=1; i--){
                if(b[i] == '0') {
                    mv.pb({i,i+1});
                    mv.pb({i+1,i+2});
                }
            }
            cout<<mv.size()<<"\n";
            for(auto p:mv) cout<<p.f<<" "<<p.s<<"\n";
        }
    }

}


详细

Test #1:

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

input:

3
1
111
110110
1101010
1111
111111

output:

-1
30
6 6
4 5
5 7
3 4
2 3
3 5
1 2
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
5 6
5 6
6 7
6 7
7 8
4 5
5 6
2 3
3 4
20
5 4
3 4
4 6
2 3
3 5
1 2
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:

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