QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637920 | #8058. Binary vs Ternary | ucup-team5071 | WA | 0ms | 3936kb | C++20 | 4.5kb | 2024-10-13 14:23:54 | 2024-10-13 14:23:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
const bool TEST = true;
struct S{
string s;
vector<pair<int,int>> ans;
int cntB1;
string hiddens;
string myA,myB;
string change(const string& s){
// cout << "change: " << s;
int num = 0;
int mul = 1;
for (int i = s.size()-1; i >= 0; --i){
num += (s[i]-'0')*mul;
mul *= 3;
}
string ret;
if (num == 0) {
ret.push_back('0');
}
while(num){
ret.push_back((num&1)+'0');
num >>= 1;
}
reverse(ret.begin(),ret.end());
// cout << " " << ret << endl;
return ret;
}
void outputans(){
// return ;
// assert(hiddens == myB);
assert(ans.size() <= 512);
// return ;
cout << ans.size() << "\n";
for(auto [x,y] : ans){
cout << x << " " << y << "\n";
}
}
void addans(int x,int y){
// cout << "op: " << x << " " << y << endl;
// cout << hiddens << endl << "\n";
if (x < 0 || y < 0){
cout << myA << " " << myB << endl;
}
assert(x >= 0 && y >= 0);
// cout << "concentation: " << endl;
// cout << hiddens.substr(0,x) << endl;
// cout << change(hiddens.substr(x,y-x+1)) << endl;
// cout << hiddens.substr(y+1,hiddens.size()-1-y) << endl;
// cout << "ENDcon" << endl;
if (TEST){
hiddens = hiddens.substr(0,x)+change(hiddens.substr(x,y-x+1))+hiddens.substr(y+1,hiddens.size()-1-y);
}
// cout << hiddens << endl;
ans.push_back(mp(x+1,y+1));
}
bool sol(const string& A,const string& B){
myA = A; myB = B;
if (A.size() == 1) {
if (B.size() == 1){ cout << 0 << "\n";}
else {cout << -1 << "\n";}
return false;
}
ans.clear();
cntB1 = 0;
for (auto ch : B){
if (ch == '1') cntB1++;
}
hiddens = A;
s = A;
for (int i = 0; i < s.size(); ++i){
if (s[i] == '0'){
addans(i-1,i);
s[i] = '1';
}
}
// 变为全1
// cout << "FULL1: " << hiddens << endl;
// cout << "cntB1: " << cntB1 << endl;
// return false;
int cntA1 = s.size();
if (cntB1 == 1){
while(cntA1 != 2){
addans(s.size()-3,s.size()-2);
addans(s.size()-1,s.size());
addans(s.size()-2,s.size()-1);
s.pop_back();
cntA1--;
}
// cout << "s: " << s << endl;
int cnt0 = B.size()-1;
addans(0,1);
for(cnt0 = 2; cnt0 < B.size()-1; ++cnt0){
addans(0,1);
addans(0,1);
s.push_back('0');
}
// if (hiddens != B){
// cout << "WA:" << endl;
// cout << "A:" << A << endl << "B: " << B << endl << "ANS: " << hiddens << endl;
// }
outputans();
return false;
}
//留到cntB1个1
if (cntA1 < cntB1){
while(cntA1 != cntB1){
addans(s.size()-2,s.size()-1);
addans(s.size()-2,s.size()-1);
s.push_back('1');
addans(s.size()-2,s.size()-1);
cntA1++;
}
} else if (cntA1 > cntB1){
while(cntA1 != cntB1){
addans(s.size()-3,s.size()-2);
addans(s.size()-1,s.size());
addans(s.size()-2,s.size()-1);
s.pop_back();
cntA1--;
}
}
// cout << "cntB1 1: " << hiddens << endl;
//加上B从后往前的0
int last1ind = B.size()-1;
int start = s.size()-2;
for (;B[last1ind] == '0'; --last1ind){
addans(start,start+1);
addans(start,start+1);
s.push_back('0');
}
// cout << "ADD SUF 0: " << hiddens << endl;
// cout << last1ind << endl;
// return false;
int ind = 0;
while(ind != last1ind){
while(B[ind+1] == '1'){
ind++;
}
if (ind == last1ind) break;
// ind--;
int nxt1;
for (nxt1 = ind+1; B[nxt1] != '1'; ++nxt1) {}
addans(ind,ind+1);
addans(ind,ind+1);
addans(ind+1,ind+2);
addans(ind,ind+1);
if (nxt1 - ind == 2){
addans(ind+1,ind+2);
} else {
for (int zcnt = 3; zcnt <= nxt1-ind-1; ++zcnt){
addans(ind,ind+1);
addans(ind,ind+1);
}
}
ind = nxt1;
}
// if (hiddens != B){
// cout << "WA:" << endl;
// cout << "A:" << A << endl << "B: " << B << endl << "ANS: " << hiddens << endl;
// }
// cout << "ans: " << hiddens << "\n";
outputans();
return true;
}
} sct;
void solve(){
string A,B;
cin >> A >> B;
// int la = rand()%62+2;
// int lb = rand()%62+2;
// A.push_back('1');
// B.push_back('1');
// for (int i = 0; i < la; i++){
// A.push_back('0'+(rand()%2));
// }
// for (int i = 0; i < lb; i++){
// B.push_back('0'+(rand()%2));
// }
// cout << A << " " << B << endl;
sct.sol(A,B);
}
int main(){
srand(time(0));
ios_base::sync_with_stdio(0);
cin.tie(0);
int T;cin >> T;
// int T = 1000000;
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 20 2 3 5 6 4 5 6 7 5 6 3 4 5 6 4 5 3 4 3 4 2 3 2 3 3 4 2 3 3 4 4 5 4 5 5 6 4 5 5 6 6 3 4 3 4 4 5 4 5 4 5 5 6
result:
ok Haitang Suki (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3936kb
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:
8 3 4 4 5 3 4 5 6 4 5 2 3 4 5 3 4 -1 13 1 2 2 3 3 4 3 4 5 6 4 5 2 3 4 5 3 4 1 2 3 4 2 3 1 2 1 1 2 6 1 2 1 2 1 2 2 3 2 3 2 3 8 2 3 3 4 2 3 4 5 3 4 1 2 3 4 2 3 11 2 3 4 5 3 4 5 6 4 5 2 3 4 5 3 4 1 2 3 4 2 3 4 2 3 1 2 3 4 2 3 -1 12 1 2 4 5 3 4 5 6 4 5 2 3 4 5 3 4 1 2 3 4 2 3 1 2 10 1 2 1 2 1 2 2 3 2 3 ...
result:
wrong answer S!=T after all operations (test case 3)