QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771447 | #8058. Binary vs Ternary | Tomorrow# | WA | 3ms | 3668kb | C++17 | 2.2kb | 2024-11-22 13:06:20 | 2024-11-22 13:06:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
string s;
i64 flag, n, m, num1;
i64 a[1005];
i64 b[1005];
vector<pair<i64,i64>> res;
void remove0(){
for(int i = 1; i <= n; i++){
if(a[i] == 0){//10 -> 11
res.push_back(make_pair(i-1, i));
a[i] = 1;
}
}
return;
}
//1111 11 11111 100
// 11
void remove1(){
i64 n1 = n;
for(int i = n1; i >= 2; i--){
res.push_back(make_pair(i-1,i));//11 -> 100
n++;
}
//100000
res.push_back(make_pair(2, n));
n = 2;
//10
res.push_back(make_pair(1,2));
//11
a[1] = a[2] = 1;
return;
}
void getans(){
//11 100 110 111 11 1
//11 100 110 11 0
for(int i = m; i >= 3; i--){
if(b[i] == 0){
res.push_back(make_pair(1,2));
n++;
res.push_back(make_pair(1,2));
}
else{
res.push_back(make_pair(1,2));
n++;
res.push_back(make_pair(1,2));
res.push_back(make_pair(2,3));
}
}
if(b[2] == 0){
res.push_back(make_pair(1,2));
res.push_back(make_pair(2,3));
}
return;
}
void solve(){
num1 = 0;
flag = 1;
res.clear();
s.clear();
cin >> s;
n = s.length();
for(int i = 1; i <= s.length(); i++){
a[i] = s[i-1] - '0';
}
s.clear();
cin >> s;
m = s.length();
for(int i = 1; i <= s.length(); i++){
b[i] = s[i-1] - '0';
if(b[i] == 1){
num1++;
}
}
if(n == 1){
if(m == 1 && a[1] == b[1]){
cout << 0 << endl;
}
else{
cout << -1 << endl;
}
return;
}
remove0();
remove1();
getans();
cout << res.size() << endl;
for(int i = 0; i < res.size(); i++){
cout << res[i].first << ' ' << res[i].second << endl;
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
if(fopen("test.in","r"))
{
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
}
i64 tt = 1;
cin >> tt;
while(tt--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3668kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 21 2 3 5 6 5 6 4 5 3 4 2 3 1 2 2 11 1 2 1 2 1 2 1 2 1 2 2 3 1 2 1 2 1 2 1 2 2 3 1 2 1 2 17 3 4 2 3 1 2 2 7 1 2 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: 3ms
memory: 3668kb
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:
11 3 4 4 5 4 5 3 4 2 3 1 2 2 9 1 2 1 2 1 2 2 3 -1 11 1 2 2 3 3 4 4 5 3 4 2 3 1 2 2 9 1 2 1 2 2 3 12 1 2 3 4 2 3 1 2 2 7 1 2 1 2 1 2 2 3 1 2 1 2 2 3 9 1 2 1 2 2 3 1 2 1 2 1 2 1 2 1 2 2 3 7 2 3 3 4 3 4 2 3 1 2 2 7 1 2 8 2 3 4 5 4 5 3 4 2 3 1 2 2 9 1 2 5 2 3 2 3 1 2 2 5 1 2 -1 10 1 2 4 5 4 5 3 4 2 3 1 ...
result:
wrong answer S!=T after all operations (test case 13)