QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#739440 | #8058. Binary vs Ternary | lixp# | WA | 1ms | 3716kb | C++17 | 2.6kb | 2024-11-12 21:46:14 | 2024-11-12 21:46:15 |
Judging History
answer
#include<bits/stdc++.h>
#define mk make_pair
using namespace std;
const int N=500;
vector<pair<int,int> > ans;
void change1(int l) {// 11 -> 111
pair<int,int> t;
t.first=l; t.second=l+1; ans.push_back(t);
t.first=l; t.second=l+1; ans.push_back(t);
t.first=l+1; t.second=l+2; ans.push_back(t);
}
void change2(int l) {//11 -> 110
pair<int,int> t;
t.first=l; t.second=l+1; ans.push_back(t);
t.first=l; t.second=l+1; ans.push_back(t);
}
void change3(int l) {// 111 -> 11
pair<int,int> t;
t.first=l; t.second=l+1; ans.push_back(t);
t.first=l+1; t.second=l+3; ans.push_back(t);
}
void change4(int l,int sm) {//11 -> 1 0(sm) 1
if(sm==0) return;
pair<int,int> t;
t.first=l; t.second=l+1; ans.push_back(t);
t.first=l; t.second=l+2; ans.push_back(t);
t.first=l+1; t.second=l+3; ans.push_back(t);
for(int i=2;i<=sm;i++) {
t.first=l; t.second=l+1; ans.push_back(t);
t.first=1; t.second=l+1; ans.push_back(t);
}
}
char s[N],t[N];
int n,m;
void solve() {
scanf("%s%s",s+1,t+1); int sum=0;
n=strlen(s+1); m=strlen(t+1);
if(strcmp(s+1,t+1)==0) {cout<<"0\n"; return;}
if(n==1) {cout<<"-1\n"; return;}
for(int i=n,lst=0;i>=1;i--) {
while(s[i]=='0') i--;
if(!lst) {
if(i==n) { sum+=1; lst=n; continue;}
if(i!=n-1) {
pair<int,int> t;
t.first=i+1; t.second=n; ans.push_back(t);
}
pair<int,int> t; t.first=i; t.second=i+1;
ans.push_back(t); sum+=2; lst=i;
} else {
pair<int,int> t;
t.first=i+1; t.second=lst; ans.push_back(t);
if(i+1==lst) ans.pop_back();
lst=i; sum++;
}
}
for(int i=3;i<=sum;i++) change3(1);
int ed=2; while(ed<=m && t[ed]=='0') ed++;
if(ed==m+1) {
for(int i=3;i<=m;i++) {
pair<int,int> t;
t.first=1,t.second=2; ans.push_back(t);
t.first=1,t.second=2; ans.push_back(t);
}
pair<int,int> t;
t.first=1,t.second=2; ans.push_back(t);
t.first=2,t.second=3; ans.push_back(t);
cout<<ans.size()<<"\n";
for(auto it:ans) cout<<it.first<<" "<<it.second<<"\n";
return;
}
for(int i=m;i>ed;i--) {
if(t[i]=='0') change2(1);
else change1(1);
}
change4(1,ed-2);
cout<<ans.size()<<"\n";
for(auto it:ans) cout<<it.first<<" "<<it.second<<"\n";
}
void init() {
ans.clear();
}
int main() {
int T;scanf("%d",&T);
while(T--) {
init(); solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3716kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 20 5 6 3 4 1 2 2 4 1 2 2 4 1 2 2 4 1 2 1 2 1 2 1 2 2 3 1 2 1 2 1 2 1 2 2 3 1 2 1 2 16 1 2 2 4 1 2 2 4 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3
result:
ok Haitang Suki (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3716kb
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 3 4 1 2 2 4 1 2 2 4 1 2 1 2 2 3 -1 3 2 5 1 2 2 3 9 2 3 1 2 2 4 1 2 1 2 2 3 1 2 1 2 2 3 6 1 2 1 2 1 2 1 2 1 2 2 3 4 3 4 2 3 1 2 2 4 6 4 5 3 4 1 2 2 4 1 2 2 4 3 2 3 1 2 2 4 -1 8 4 5 2 3 1 2 2 4 1 2 2 4 1 2 2 3 10 1 2 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 7 2 5 1 2 1 2 1 3 2 4 1 2 1 2 3 1 2 1 2 2 3...
result:
wrong answer S!=T after all operations (test case 12)