QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#465548 | #8058. Binary vs Ternary | BalintR | WA | 0ms | 3628kb | C++20 | 2.9kb | 2024-07-07 01:18:50 | 2024-07-07 01:18:51 |
Judging History
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) 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');
}
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());
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
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 29 3 4 1 2 2 3 2 3 1 2 2 3 2 3 1 2 2 3 2 3 1 2 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 4 5 4 5 3 4 3 4 2 3 2 3 1 2 2 3 2 3 24 1 2 2 3 2 3 1 2 2 3 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 2 2 3 2 3
result:
ok Haitang Suki (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3628kb
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:
17 4 5 1 2 2 3 2 3 1 2 2 3 2 3 1 2 1 2 1 2 2 3 1 2 1 2 2 3 1 2 2 3 2 3 -1 8 2 3 2 3 2 3 1 2 1 2 1 2 2 3 2 3 16 2 3 1 2 2 3 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 2 2 3 2 3 12 1 2 1 2 1 2 2 3 1 2 1 2 2 3 3 4 3 4 1 2 2 3 2 3 11 3 4 1 2 2 3 2 3 1 2 1 2 1 2 2 3 1 2 2 3 2 3 14 3 4 1 2 2 3 2 3 1 2 2 3 ...
result:
wrong answer (l,r) is invalid (test case 13)