QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#380901 | #8058. Binary vs Ternary | ucup-team2230# | WA | 3ms | 3868kb | C++23 | 3.0kb | 2024-04-07 14:44:06 | 2024-04-07 14:44:06 |
Judging History
answer
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using uint=unsigned;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())
#define a first
#define b second
template<class t>using vc=vector<t>;
template<class t,class u>bool chmax(t&a, u b){ if(a<b){a=b;return 1;}return 0;}
template<class t,class u>bool chmin(t&a,u b){if(a>b){a=b;return 1;}return 0;}
using P=pair<int,int>;
template<class t,class u>
ostream& operator<<(ostream& os, const pair<t,u>&p){
return os<<"{"<<p.a<<","<<p.b<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>&v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
void solve(){
string s,t;cin>>s>>t;
if(s == t){
cout<<0<<endl; return;
}
if(s == "1" or t == "1"){
cout<<-1<<endl; return;
}
vc<P>ans;
while(1){
rep(i,si(s)){
if(s[i] == '0'){
rng(j,i+1,si(s)){
if(s[j] == '1'){
ans.eb(i, j);
string ss = s.substr(0,i)+s.substr(j);
s = ss; //cout<<s<<endl;
goto nxt;
}
}
//all zero
rng(j,i-1,si(s)-1){
//10->11
ans.eb(j,j+1);
s[j+1]='1';
goto nxt2;
}
}
}break;
nxt:;
}
nxt2:;
//cout<<ans<<endl;
while(si(s) > 2){
ans.eb(0,1);
ans.eb(1,3);
s.pop_back();
}
//s = 11
int md;
int m = si(t);
int len;
if(t[m-1] == '0') md = 0;
else{
for(int i=m-1;i>=-1;i--){
if(i == -1 or t[i] == '0'){
if(i == m-2){
md = 1;
}
else{
md = 2;
len = (m-2-i);
rng(j,i+2,m) t[j] = '0';
}
break;
}
}
}
//cout<<t<<endl;
vc<int>L;
char c;
int cur;
rep(i,m){
if(!i) c=t[i],cur=1;
else if(c==t[i]) cur++;
else{
L.pb(cur);
c=t[i],cur=1;
}
}
L.pb(cur);
//cout<<L<<" "<<t<<" "<<md<<endl;
if(si(L)%2 == 1){
assert(md == 1);
L.pop_back();
}
//cout << L << endl;
//11->(10)*si(L)/2
if(si(L) == 2){
ans.eb(0,1);
ans.eb(1,2);
}
else{
ans.eb(0,1); ans.eb(0,1); ans.eb(1,2); ans.eb(0,1);
ans.eb(1,2); ans.eb(0,2);
//1010
for(int i=2;i<si(L)/2;i++){
ans.eb(0,1); ans.eb(0,1); ans.eb(0,1); ans.eb(1,2); ans.eb(0,1);
ans.eb(1,2); ans.eb(0,2);
}
}
//cout<<ans<<endl;
//cout<<L<<" "<<md<<endl;
//{1,..,1}
int pre = 0;
rep(i,si(L)){
if(i%2 == 0){
rep(j,L[i]-1){
ans.eb(pre,pre+1);
ans.eb(pre,pre+1);
ans.eb(pre,pre+1);
pre++;
}
}
else{
if(i+1 == si(L) and md == 1){
ans.eb(pre,pre+1); ans.eb(pre,pre+1); ans.eb(pre,pre+1);
ans.eb(pre+1,pre+2); ans.eb(pre,pre+1);
ans.eb(pre+1,pre+2);
}
rep(j,L[i]-1){
ans.eb(pre,pre+1);
ans.eb(pre,pre+1);
}
if(i+1 == si(L) and md == 2){
rep(j,len){
ans.eb(pre,pre+1);
pre++;
}
}
pre += L[i]+1;
}
}
cout << si(ans) << endl;
for(auto [x,y]:ans) cout<<x+1<<" "<<y+1<<endl;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int t;cin>>t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 24 3 4 4 5 1 2 2 4 1 2 2 4 1 2 2 4 1 2 1 2 2 3 1 2 2 3 1 3 1 2 1 2 1 2 2 3 1 2 2 3 1 3 1 2 1 2 1 2 19 1 2 2 4 1 2 2 4 1 2 2 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 3 3 4 4 5 5 6
result:
ok Haitang Suki (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3868kb
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:
13 3 4 1 2 2 4 1 2 2 4 1 2 2 4 1 2 2 3 1 2 1 2 1 2 2 3 -1 3 2 5 1 2 2 3 12 2 3 1 2 2 4 1 2 2 3 1 2 1 2 1 2 1 2 1 2 2 3 3 4 9 1 2 1 2 2 3 1 2 1 2 1 2 2 3 2 3 2 3 8 2 3 1 2 2 4 1 2 2 4 1 2 2 3 1 2 9 3 4 3 4 1 2 2 4 1 2 2 4 1 2 2 3 1 2 6 2 3 1 2 2 4 1 2 2 3 1 2 -1 8 2 3 3 4 1 2 2 4 1 2 2 4 1 2 2 3 13 1...
result:
wrong answer (l,r) is invalid (test case 1)