Tsukihjy's picture
download
raw
2.85 kB
import random
import string
def generate_random_string(length):
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))
def generate_operations(num_ops, initial_length):
operations = []
current_length = initial_length
for _ in range(num_ops):
op_type = random.choices(['Q', 'R', 'I'], weights=[0.4, 0.3, 0.3])[0]
if op_type == 'Q':
if current_length >= 2:
x = random.randint(1, current_length)
y = random.randint(1, current_length)
operations.append(f"Q {x} {y}")
else:
operations.append(f"Q 1 1")
elif op_type == 'R':
if current_length >= 1:
x = random.randint(1, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"R {x} {d}")
elif op_type == 'I':
x = random.randint(0, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"I {x} {d}")
current_length += 1
return operations
def construct_inputs():
inputs = []
# Small test cases
for _ in range(10):
initial_string = generate_random_string(random.randint(1, 20))
num_ops = random.randint(1, 30)
operations = generate_operations(num_ops, len(initial_string))
test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations)
inputs.append(test_case)
# Medium test cases
for _ in range(10):
initial_string = generate_random_string(random.randint(50, 500))
num_ops = random.randint(100, 1000)
operations = generate_operations(num_ops, len(initial_string))
test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations)
inputs.append(test_case)
# Large test cases
for _ in range(10):
initial_string = generate_random_string(random.randint(1000, 10000))
num_ops = random.randint(5000, 50000)
operations = generate_operations(num_ops, len(initial_string))
test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations)
inputs.append(test_case)
# Edge cases
# Single character string
initial_string = "a"
operations = ["Q 1 1", "R 1 b", "Q 1 1", "I 0 c", "Q 1 2"]
test_case = initial_string + '\n' + str(len(operations)) + '\n' + '\n'.join(operations)
inputs.append(test_case)
# Maximum constraints
initial_string = generate_random_string(100000)
num_ops = 150000
operations = generate_operations(num_ops, len(initial_string))
test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations)
inputs.append(test_case)
return inputs

Xet Storage Details

Size:
2.85 kB
·
Xet hash:
b976bd7d4de32d7d94370aa8f823a4b57b9dca8d2ece56ecc717b3f5d7524735

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.