QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627884 | #8058. Binary vs Ternary | tjf4 | WA | 1ms | 3872kb | C++20 | 2.9kb | 2024-10-10 17:30:13 | 2024-10-10 17:30:15 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<char> vc;
const ll inf=1e18;
const int N=5e5+10;
int n,m,a[N],ls[N];
string s,t;
vii g;
//10->11
//11->100
//00->0
//100->10
void init(int &n,string &s,string &now) {
s=now; n=s.size(); now="";
}
void upd(int l,int r,int op) {
if(op==0) g.push_back({l,r});
else {
g.push_back({r-1,r});
g.push_back({r,r+1});
while(l<r-1) {
g.push_back({r-2,r-1});
g.push_back({r-1,r+1});
r--;
}
}
}
void get_10() {
string as;
for(int i=1;i<=n;i++) {
if(s[i-1]=='1') as+='1';
else {
int j=i;
while(j<=n&&s[i-1]==s[j-1]) j++;
int cnt=j-i+1;
if(j>n) {
g.push_back({as.size()+1,as.size()+cnt-1});
as+='0';
}
else {
g.push_back({as.size()+1,as.size()+cnt});
as+='1';
}
i=j;
}
}
init(n,s,as);//s->1...1 or 1...10
if(s=="10") return;
if(s.back()=='1') upd(1,n,1);
else upd(1,n-1,1),upd(2,3,0);
}
void add0(int l,int r) {//10->100
g.push_back({l,r});
g.push_back({l,r});
}
void add(int l,int r,int op,int now) {//10->010 or 110
if(op==1) {
g.push_back({l,r});
g.push_back({l,r});
g.push_back({l,r});
}
else if(a[now-1]=='1') {
g.push_back({l,r});
g.push_back({l,r});
g.push_back({l,r});
r=l; l=l-1;
g.push_back({r-1,r});
g.push_back({r,r+1});
}
else {
int lf=ls[now];
g.push_back({lf,lf+1});
g.push_back({lf,lf+1});
}
}
int main() {
IOS
int T;
cin>>T;
while(T--) {
cin>>s>>t;
n=s.size();
m=t.size();
if(s==t) {
cout<<0<<'\n';
continue;
}
else if(s.size()==1) {
cout<<-1<<'\n';
continue;
}
else if(t.size()==1) {
cout<<-1<<'\n';
continue;
}
else {
g.clear();
get_10();
s="10"; n=2;
for(int i=1;i<=m;i++) {
if(t[i-1]=='1') ls[i]=i;
else ls[i]=ls[i-1];
a[i]=t[i-1]-'0';
}
for(int i=1;i<=m;i++) {
if(t[i-1]=='1') add(n-1,n,1,i);
else add(n-1,n,0,i);
n++;
}
if(a[m]+a[m-1]==2) {
upd(n-3,n-1,1); n--;
upd(n-1,n,0); n--;
g.push_back({m-1,m});
}
else if(a[m]+a[m-1]==0) {
int lf=ls[m];
g.push_back({lf+1,n-1}); n-=(m-lf);//10...010->110
upd(lf,lf+1,1);//110->100
while(n<m) add0(lf,lf+1),n++;//100->10...0
}
else if(a[m]==1) {//110
g.push_back({n-1,n});//110->111
upd(n-2,n,1); n--; //111->10
g.push_back({n-1,n});//10->11
int lf=ls[m-1];
g.push_back({lf+1,m}); n-=(m-lf-1); //1...011->111
upd(lf,lf+1,1);//111->101
while(n<m) add0(lf,lf+1),n++;//101->10...01
}
else if(a[m-1]==1) {
g.push_back({n-3,n-2});
upd(n-3,n-1,1); n--;
upd(n-1,n,0); n--;
}
cout<<g.size()<<'\n';
for(auto v:g) cout<<v.first<<' '<<v.second<<'\n';
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3872kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 33 3 4 5 5 3 4 4 5 2 3 3 5 1 2 2 4 2 3 1 2 1 2 1 2 2 3 2 3 2 3 2 3 2 3 4 5 4 5 4 5 4 5 4 5 6 7 6 7 6 7 6 7 6 7 6 7 7 8 8 9 6 7 7 9 7 8 30 3 4 4 5 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 6 7 6 7 7 8 5 6 6 8 6 7 5 6
result:
wrong answer (l,r) is invalid (test case 2)