QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#842027#9075. Bits Reverse1903331632AC ✓29ms3672kbC++231.9kb2025-01-04 09:42:572025-01-04 09:42:57

Judging History

This is the latest submission verdict.

  • [2025-01-04 09:42:57]
  • Judged
  • Verdict: AC
  • Time: 29ms
  • Memory: 3672kb
  • [2025-01-04 09:42:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int op;
void solve()
{
    int a, b;
    cin >> a >> b;
    string s1 = "";
    string s2 = "";
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    int c4 = 0;
    while (a > 0)
    {
        int t = a % 2;
        a /= 2;
        s1 += to_string(t);
    }
    while (b > 0)
    {
        int t = b % 2;
        b /= 2;
        s2 += to_string(t);
    }
    while (s1.size() < s2.size())
        s1 += "0";
    while (s2.size() < s1.size())
        s2 += "0";
    for (int i = 0; i < s1.size(); i++)
    {
        if (s1[i] == '1')
        {
            if (i & 1)
                c1++;
            else
                c2++;
        }
        if (s2[i] == '1')
        {
            if (i & 1)
                c3++;
            else
                c4++;
        }
    }
    if (c1 != c3 || c2 != c4)
    {
        cout << "Case " << ++op << ": " << -1 << endl;
        return;
    }
    int cnt = 0;
    for (int i = 0; i < s1.size(); i++)
    {
        if (s1[i] != s2[i])
        {
            int j = i;
            if (s1[i] == '0')
            {
                while (j < s1.size() && s1[j] == '0')
                {
                    cnt++;
                    j += 2;
                }
                s1[j] = '0';
                s1[i] = '1';
            }
            else
            {
                while (j < s1.size() && s2[j] == '0')
                {
                    cnt++;
                    j += 2;
                }
                s2[j] = '0';
                s2[i] = '1';
            }
        }
    }
    cout << "Case " << ++op << ": " << cnt << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0 3
3 6
6 9

output:

Case 1: -1
Case 2: 1
Case 3: 2

result:

ok 9 tokens

Test #2:

score: 0
Accepted
time: 29ms
memory: 3672kb

input:

10000
7710 15375
973222 834469
471452 56651
188265 356262
937670 799667
271275 139758
478003 921397
326270 989759
660733 773404
704847 823278
657246 469149
175141 657754
885471 995694
100976 10574
184105 671365
194858 212648
181670 412313
361081 15451
632193 21228
745707 981594
911635 884353
863600 ...

output:

Case 1: 4
Case 2: 13
Case 3: 12
Case 4: 16
Case 5: 9
Case 6: 11
Case 7: 18
Case 8: 8
Case 9: 17
Case 10: -1
Case 11: 18
Case 12: 14
Case 13: 12
Case 14: 11
Case 15: 12
Case 16: 8
Case 17: 12
Case 18: 10
Case 19: 19
Case 20: -1
Case 21: 11
Case 22: 14
Case 23: 9
Case 24: 6
Case 25: 6
Case 26: 7
Case ...

result:

ok 30000 tokens

Extra Test:

score: 0
Extra Test Passed