QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#742620 | #8058. Binary vs Ternary | quark404# | WA | 83ms | 10720kb | Python3 | 3.3kb | 2024-11-13 16:55:32 | 2024-11-13 16:55:32 |
Judging History
answer
ans = []
def count_leading_zero(s: str) -> int:
res = 0
for c in s:
if (c == '0'): res += 1
else: break
return res
def modify(s: str, l: int, r: int, base: int = 0) -> str:
# assert(base == 0)
if (l >= r): return s
src = s[l:r + 1]
src = int(src, base=3)
src = bin(src)[2:]
ans.append((l + 1 + base, r + 1 + base, f"before: {s}, after: {s[:l] + src + s[r + 1:]}"))
return s[:l] + src + s[r + 1:]
def erase_trailing_zero(s: str, base: int) -> str:
l, r = len(s) - 1, len(s) - 1
while (l >= 0 and s[l] == '0'): l -= 1
l += 1
assert(l >= 1)
return modify(s, l, r, base)
def change_last_digit(s: str, base: int):
l = len(s) - 2
while (s[l] == '0'): l -= 1
assert(l >= 1)
assert(len(s) >= 4)
s = modify(s, l, len(s) - 1, base)
return s
# if (s[-1] == '1'):
# s = s[:-1]
# s = erase_trailing_zero(s, base)
# s = s + '1'
# if (s[:-2] == '0'):
# return modify(s, len(s) - 3, len(s) - 1, base)
# else:
# return modify(s, len(s) - 2, len(s) - 1, base)
# else:
# s = erase_trailing_zero(s, base)
# return modify(s, len(s) - 2, len(s) - 1, base)
def cleanup(s: str, base: int):
for i in range(1, len(s)):
if (s[i] == '0'):
s = modify(s, i - 1, i, base)
for i in range(len(s) - 1, 0, -1):
s = modify(s, i - 1, i, base)
s = erase_trailing_zero(s, base)
return s
def solve() -> None:
ans.clear()
s = input()
t = input()
# 1) remove all leading 0's
# s_lz = count_leading_zero(s)
# t_lz = count_leading_zero(t)
# if (s_lz < t_lz):
# print(-1)
# return
# s = modify(s, 0, s_lz - t_lz)
# base = count_leading_zero(s)
# s, t = s[base:], t[base:]
base = 0
# print("1st: ", s, t)
# 2) check if s == 1 or t == 1
if (len(s) == 1 or len(t) == 1):
if (s != t):
print(-1)
else:
print(len(ans))
for (l, r, _) in ans:
print(l, r)
return
# print("2nd: ", s, t)
assert (len(s) >= 2)
# 至多操作两次长度即为3
if (len(s) == 2): s = modify(s, 0, 1, base)
if (len(s) == 2): s = modify(s, 0, 1, base)
assert (len(s) >= 3)
# 3) expand s to length(t)
while (len(t) > 2):
assert(len(s) >= 3)
# 保证第2位是1且长度至少为4
if (len(s) == 3): s = modify(s, 0, 2, base)
if (s[1] == '0'): s = modify(s, 0, 1, base)
if (s[-1] != t[-1]):
s = change_last_digit(s, base)
s, t = s[:-1], t[:-1]
s = erase_trailing_zero(s, base)
# print("3rd in progress: ", s, t)
# print("3rd: ", s, t)
# 4) cleanup
s = cleanup(s, base)
# print("4th: ", s, t)
# 5) check if s != t
if (t == '11'):
s = modify(s, 0, 1, base)
assert(s == t)
if (len(ans) > 512):
while True:
pass
print(len(ans))
for (l, r, debug) in ans:
print(l, r)
# print(debug)
def main():
t = int(input())
for _ in range(t): solve()
if (__name__ == "__main__"):
main()
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 10612kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 7 2 4 1 3 2 3 2 3 1 2 2 5 1 2 12 1 3 1 3 2 4 3 4 1 3 2 4 3 4 2 3 2 3 1 2 2 5 1 2
result:
ok Haitang Suki (3 test cases)
Test #2:
score: 0
Accepted
time: 18ms
memory: 10656kb
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 5 4 5 3 4 3 4 2 3 1 2 2 7 1 2 -1 8 1 2 2 3 3 4 4 5 3 4 2 3 1 2 2 9 7 1 2 1 3 2 3 2 3 1 2 2 5 1 2 10 1 2 1 2 1 3 1 2 2 4 2 3 2 3 1 2 2 5 1 2 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 7 1 2 4 5 4 5 3 4 2 3 1 2 2 9 15 1 2 1 2 1 3 1 2 1 3 2 4 3 4 1 3 2 ...
result:
ok Haitang Suki (1000 test cases)
Test #3:
score: 0
Accepted
time: 15ms
memory: 10584kb
input:
1000 1110 110 1 11 1110 110 101 111 100 1001 10 110 1001 10011 10 11010 100 111 1101 1001 1 111 1 1 11 1 1011 1101 1 11 111 10 100 1110 1001 10 10 11 1 10 11 11 111 1100 10100 11001 10 110 1001 101 1 10011 100 10 10110 111 1100 110 11010 11 1000 1101 1010 1 1100 100 11010 1 1011 1 11001 1110 11 1110...
output:
4 2 3 1 2 2 5 1 2 -1 4 2 3 1 2 2 5 1 2 7 1 3 1 2 3 4 2 3 1 2 2 5 1 2 7 1 3 1 2 1 3 2 3 2 3 1 2 2 5 11 1 2 1 2 1 3 1 2 2 4 2 3 3 4 2 3 1 2 2 7 1 2 9 1 2 1 3 2 4 3 4 1 3 2 3 2 3 1 2 2 5 11 1 2 1 2 1 3 1 2 2 4 1 3 2 3 2 3 1 2 2 5 1 2 7 1 3 1 2 2 3 2 3 1 2 2 5 1 2 5 1 3 2 3 2 3 1 2 2 5 -1 0 -1 9 1 2 1 3...
result:
ok Haitang Suki (1000 test cases)
Test #4:
score: 0
Accepted
time: 21ms
memory: 10656kb
input:
1000 11110010 11110001 11010110 1001 11011110 1001110 111101100 111111100 110 101111001 10000100 10 1100100 101010 100 1000 1011110 110101 1001 10001111 100011111 1001111011 1110100 1010 1001100001 1000 11 101101 1000001111 11100 101001101 1 11 111001111 100101101 10 1 10111 1111000111 1101 10111 11...
output:
9 7 8 4 7 5 6 5 6 3 4 2 3 1 2 2 7 1 2 12 7 8 6 7 2 3 4 5 6 7 6 7 5 6 4 5 3 4 2 3 1 2 2 13 6 2 4 2 3 3 4 2 3 1 2 2 7 7 4 5 1 3 2 3 2 3 1 2 2 5 1 2 21 1 3 2 4 3 4 1 3 1 3 1 3 2 4 3 4 1 3 2 4 3 4 1 3 2 4 3 4 1 3 2 4 3 4 2 3 2 3 1 2 2 5 14 1 2 2 3 3 4 4 5 6 7 7 8 7 8 6 7 5 6 4 5 3 4 2 3 1 2 2 15 7 5 6 2...
result:
ok Haitang Suki (1000 test cases)
Test #5:
score: 0
Accepted
time: 26ms
memory: 10656kb
input:
1000 11 10 1111101 10 1011010001 1101010100 101110 101101001 110 110 100001 1111 10 1001100 1101101000 1 1 1110 11 1110000 110111010 1001000 110100000 1 1110101001 10 11111 1001101 110 1110 111 11 11000 1 111111 1 101111111 1100100100 101101100 1111110 10001 1001 1100110100 100 1001 101001 100011000...
output:
6 1 2 1 2 2 3 2 3 1 2 2 5 8 5 6 6 7 5 6 4 5 3 4 2 3 1 2 2 13 20 1 2 6 10 8 11 10 11 9 10 9 10 8 9 8 9 6 8 4 5 6 7 7 8 6 7 5 6 4 5 3 4 2 3 1 2 2 15 1 2 12 1 2 5 6 4 5 1 3 2 4 1 3 2 4 3 4 2 3 2 3 1 2 2 5 6 1 3 2 3 2 3 1 2 2 5 1 2 10 1 2 3 5 1 3 2 4 3 4 2 3 2 3 1 2 2 5 1 2 14 1 2 1 2 1 3 1 2 2 4 2 4 1 ...
result:
ok Haitang Suki (1000 test cases)
Test #6:
score: 0
Accepted
time: 26ms
memory: 10720kb
input:
1000 1010100001 1101101111 1000001111 1100000010 1101001000 1111011000 1011010000 1101111100 1000011000 1001010110 1100010110 1001001000 1000111110 1101100000 1101011010 1111000101 1110111001 1000000010 1111110000 1001100000 1000010111 1010101110 1110101000 1111100001 1110110101 1011100001 110111101...
output:
15 1 2 6 9 5 6 3 4 1 3 2 4 1 3 2 4 3 4 1 3 2 3 2 3 1 2 2 5 1 2 15 1 2 9 10 9 10 8 9 7 8 2 7 5 6 6 7 5 6 4 5 3 4 2 3 1 2 2 13 1 2 10 8 9 4 7 6 7 4 5 4 5 2 3 2 3 1 2 2 5 1 2 13 1 2 7 9 4 5 1 3 1 3 2 4 3 4 1 3 2 3 2 3 1 2 2 5 1 2 10 1 2 8 9 7 8 2 6 5 6 1 3 2 3 2 3 1 2 2 5 8 8 9 2 6 5 6 2 3 3 4 2 3 1 2 ...
result:
ok Haitang Suki (1000 test cases)
Test #7:
score: 0
Accepted
time: 34ms
memory: 10596kb
input:
1000 1010010100 1100011110 1111100001 1110100100 1001011000 1001011110 1110100101 1000001010 1110010010 1110110010 1010001000 1110011110 1010101110 1100011011 1000000100 1100100001 1010001011 1111101100 1001110101 1010001011 1001001010 1010010111 1011001010 1110001111 1000001000 1111001011 100111101...
output:
13 1 2 8 9 6 7 4 5 1 3 2 4 2 4 2 3 3 4 2 3 1 2 2 7 1 2 12 5 10 7 8 7 8 6 7 6 7 5 6 4 5 3 4 2 3 1 2 2 11 1 2 10 1 2 8 9 7 8 4 5 2 4 1 3 2 3 2 3 1 2 2 5 11 8 10 6 7 3 5 3 5 3 5 3 4 4 5 3 4 2 3 1 2 2 9 9 7 8 3 6 5 6 3 4 3 4 2 3 1 2 2 5 1 2 16 1 2 8 9 7 8 4 6 3 4 1 3 1 3 1 3 1 3 2 4 3 4 2 3 2 3 1 2 2 5 ...
result:
ok Haitang Suki (1000 test cases)
Test #8:
score: -100
Wrong Answer
time: 83ms
memory: 10640kb
input:
1000 10001101010010010010011111000100011110010111010011100110011 101100010110011111000010101 101111101000100010010101 10100101000010100001101000001101010111 1101110100111100111110101101101000110101010010011100 1110100100101011000011 1100001100101011010000111010111000000101 11101000100000101000001111...
output:
77 1 2 55 58 57 58 56 57 56 57 55 56 54 55 52 53 51 52 47 48 44 46 44 45 43 44 43 44 42 43 40 42 40 41 2 3 3 4 6 7 8 9 10 11 11 12 13 14 14 15 16 17 17 18 19 20 20 21 26 27 27 28 28 29 30 31 31 32 32 33 37 38 38 39 39 40 38 39 37 38 36 37 35 36 34 35 33 34 32 33 31 32 30 31 29 30 28 29 27 28 26 27 2...
result:
wrong answer too long (test case 831)