QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465559#8058. Binary vs TernaryBalintRCompile Error//C++202.9kb2024-07-07 01:30:522024-07-07 01:30:53

Judging History

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

  • [2024-07-07 01:30:53]
  • 评测
  • [2024-07-07 01:30:52]
  • 提交

answer

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

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cpx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) begin(v), end(v)
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound(ALL(v), x) - (v).begin())
#define ubv(v, x) (upper_bound(ALL(v), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cerr << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cerr << #arr; FR(_i, n) cerr << ' ' << (arr)[_i]; cerr << endl;}
template <typename T, typename U>
ostream& operator<<(ostream &os, pair<T, U> p){return os << "(" << p.fs << ", " << p.sn << ")";}

vpii ans;

bool solve(){
    string s, tgt;
    cin >> s >> tgt;
    if(s == tgt) return true;
    if(SZ(s) == 1 || SZ(t) == 1) return false;

    char *ptr;
    while((ptr = strstr(&s[0], "00"))){
        int i = ptr-&s[0];
        ans.pb({i, i+2});
        s.erase(s.begin()+i);
    }
    while((ptr = strstr(&s[0], "01"))){
        int i = ptr-&s[0];
        ans.pb({i, i+2});
        s.erase(s.begin()+i);
    }
    while(SZ(s) > 2){
        assert(s[0] == '1' && s[1] == '1');
        ans.pb({0, 2});
        ans.pb({1, 3});
        ans.pb({1, 3});
        s.erase(s.begin());
    }
    if(s == "10"){
        ans.pb({0, 2});
        s = "11";
    }
    assert(s == "11");

    vi zeroBlks;
    int cur = 0;
    FORR(i, SZ(tgt)-1, 0){
        if(tgt[i] == '0') cur++;
        else zeroBlks.pb(cur), cur = 0;
    }

    while(SZ(s) <= SZ(zeroBlks)){
        ans.pb({0, 2});
        ans.pb({0, 2});
        ans.pb({1, 3});
        s.insert(s.begin(), '1');
    }
    assert(SZ(s) == SZ(zeroBlks)+1);

    FR(i, SZ(zeroBlks)){
        int p = SZ(zeroBlks)-i;
        FR(its, zeroBlks[i]){
            ans.pb({p-1, p+1});
            ans.pb({p-1, p+1});
            s.insert(s.begin()+p+1, '0');
        }
    }

    ans.pb({0, 2});
    ans.pb({1, 3});
    ans.pb({1, 3});
    s.erase(s.begin());

    assert(s == tgt);

    return true;
}

int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        bool res = solve();
        if(!res) cout << "-1\n";
        else {
            cout << SZ(ans) << '\n';
            for(auto [l, r] : ans) cout << l+1 << ' ' << r << '\n';
        }
        ans.clear();
    }
}

Details

answer.code: In function ‘bool solve()’:
answer.code:39:25: error: ‘t’ was not declared in this scope
   39 |     if(SZ(s) == 1 || SZ(t) == 1) return false;
      |                         ^
answer.code:18:23: note: in definition of macro ‘SZ’
   18 | #define SZ(v) ((int) (v).size())
      |                       ^