QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#414875#8058. Binary vs Ternarykevinshan#WA 1ms3584kbC++172.5kb2024-05-19 23:17:542024-05-19 23:17:55

Judging History

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

  • [2024-05-19 23:17:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2024-05-19 23:17:54]
  • 提交

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;
                }
            }
            if(bk == a.size()-1) {
                mv.pb({a.size()-1, a.size()});
                mv.pb({a.size()-1, a.size()});
                sz++;
            }
            mv.pb({bk+2, sz});
            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: 100
Accepted
time: 1ms
memory: 3584kb

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
22
3 4
3 4
5 5
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:

ok Haitang Suki (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3532kb

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:

9
4 5
2 3
3 5
1 2
2 4
1 2
1 2
1 2
2 3
-1
11
4 5
4 5
6 6
4 5
3 4
2 3
1 2
2 4
1 2
1 2
2 3
15
3 4
3 4
5 5
3 4
4 6
2 3
1 2
2 4
1 2
1 2
1 2
2 3
2 3
2 3
3 4
10
2 2
1 2
1 2
1 2
2 3
2 3
2 3
3 4
3 4
4 5
4
3 4
1 2
2 4
1 2
7
5 5
3 4
2 3
3 5
1 2
2 4
1 2
4
3 3
1 2
2 4
1 2
-1
9
5 5
3 4
4 6
2 3
1 2
2 4
1 2
1 2
2 3...

result:

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