QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694577#8058. Binary vs TernarySSAABBEERRWA 0ms3564kbC++202.5kb2024-10-31 18:13:442024-10-31 18:13:53

Judging History

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

  • [2024-10-31 18:13:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2024-10-31 18:13:44]
  • 提交

answer

#include<bits/stdc++.h>
#define lowbit(x) (x & (-x))
#define endl "\n"
#define ll long long
#define int long long
using namespace std;
#define pii pair<int, int>
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define pre(i, a, b) for(int i = a; i >= b; i -- )
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int N = 1e6 + 10;
int n, m, k;
int a[N], b[N];
string g(string s)
{
    string res;
    int w = 1, sum = 0;
    pre(i, s.size() - 1, 0)
    {
        int ww = s[i] - '0';
        ww *= w;
        sum += ww;
        w *= 3;
    }
    while(sum) 
    {
        if(sum & 1) res += '1';
        else res += '0';
        sum /= 2;
    }
    reverse(res.begin(), res.end());
    return res;
}
void solve()
{
    // string s;
    // cin >> s;
    // cout<<s<<" ";
    // cout<<g(s);
    // cout<<endl;
    string x, y;
    cin >> x >> y;
    x = " " + x;
    y = " " + y;
    n = x.size() - 1, m = y.size() - 1;
    if(x == y)
    {
        cout << 0 << endl;
        return;
    }
    if(n == 1 || m == 1)
    {
        if(x != y)
        {
            cout << -1 << endl;
            return;
        }
    }
    vector<pii>ans;
    int len = n;
    pre(i, n, 1)
    {
        if(x[i] != '0') continue;
        int l = i;
        while(l - 1 >= 1 && x[l - 1] == '0') l -- ;
        ans.push_back({i, l});
        ans.push_back({l - 1, l});
        len -= (i - l);
        i = l;
    }
    x.clear();
    x += " ";
    rep(i, 1, len) x += '1';
    pre(i, len - 2, 1)
    {
        ans.push_back({i, i + 1});
    }
    if(len > 2) ans.push_back({2, 2 + (len - 2) * 2 - 1});
    n = 2;
    int now = 1;
    while(n < m)
    {
        ans.push_back({now, now + 1});
        ans.push_back({now, now + 1});
        ans.push_back({now + 1, now + 2});
        now ++ , n ++ ;
    }
    x.clear();
    x += " ";
    rep(i, 1, m) x += '1';
    rep(i, 1, m - 1)
    {
        if(y[i] == '1' && y[i + 1] == '0')
        {
            int l = i, r = i + 1;
            while(r + 1 <= m && y[r + 1] == '0') r ++ ;
            pre(j, r - 1, l)
            {
                ans.push_back({j, j + 1});
                ans.push_back({j + 1, j + 2});
            }
            i = r;
        }
    }
    cout << ans.size() << endl;
    rep(i, 0, 0)
    {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}
signed main()
{
    IOS;
    int _;
    _ = 1;
    cin >> _;
    while(_ -- )
    {
        solve();
    }
	return 0;
}

詳細信息

Test #1:

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

input:

3
1
111
110110
1101010
1111
111111

output:

-1
30
6 6
15
2 3

result:

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