CSES - Datatähti 2023 alku - Results
Submission details
Task:Kertoma
Sender:Tumppi066
Submission time:2022-11-02 21:01:18 +0200
Language:Python3 (PyPy3)
Status:READY
Result:46
Feedback
groupverdictscore
#1ACCEPTED22
#2ACCEPTED24
#30
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2, 3details
#2ACCEPTED0.05 s1, 2, 3details
#3ACCEPTED0.06 s1, 2, 3details
#4ACCEPTED0.05 s1, 2, 3details
#5ACCEPTED0.06 s1, 2, 3details
#6ACCEPTED0.06 s1, 2, 3details
#7ACCEPTED0.06 s2, 3details
#8ACCEPTED0.06 s2, 3details
#9ACCEPTED0.06 s2, 3details
#10ACCEPTED0.06 s2, 3details
#11--3details
#12--3details
#13--3details
#14--3details
#15--3details
#16--3details

Code

import math
import time
import random

# Testing factorials
# [10008, 5780, 5743, 5782, 5807, 5726, 5746, 5729, 5862, 5783]
# [9806, 5881, 5721, 5776, 5686, 5837, 5814, 5751, 5940, 5763]
# [9924, 5869, 5836, 5710, 5727, 5892, 5676, 5820, 5730, 5795]
# [9903, 5888, 5842, 5741, 5769, 5818, 5748, 5739, 5742, 5793]
# [9840, 5860, 5701, 5843, 5875, 5761, 5790, 5764, 5737, 5816]
# [9867, 5824, 5715, 5766, 5793, 5872, 5801, 5718, 5874, 5761]
# [10076, 5806, 5681, 5785, 5767, 5753, 5869, 5765, 5721, 5777]
# [9811, 5761, 5734, 5893, 5802, 5891, 5861, 5779, 5654, 5818]
# [9956, 5626, 5798, 5762, 5951, 5729, 5854, 5869, 5700, 5763]
# [9857, 5765, 5832, 5814, 5595, 5785, 5729, 5912, 5820, 5903]
# [9862, 5749, 5828, 5773, 5819, 5859, 5862, 5733, 5800, 5736]
# [9841, 5711, 5825, 5798, 5836, 5749, 5896, 5742, 5778, 5849]
# [10014, 5845, 5824, 5818, 5730, 5757, 5745, 5825, 5792, 5679]
# [9862, 5773, 5845, 5770, 5772, 5844, 5732, 5746, 5851, 5839]
# [9801, 5763, 5927, 5751, 5914, 5825, 5822, 5713, 5749, 5777]
# [9912, 5912, 5709, 5846, 5889, 5698, 5794, 5709, 5788, 5793]
# [9880, 5816, 5862, 5729, 5745, 5838, 5743, 5793, 5801, 5848]
# [9969, 5733, 5816, 5728, 5893, 5691, 5741, 5851, 5802, 5839]
# [9913, 5806, 5836, 5841, 5874, 5777, 5713, 5767, 5771, 5769]
# [9832, 5827, 5799, 5721, 5774, 5956, 5762, 5680, 5862, 5858]
# [9894, 5648, 5905, 5615, 5756, 5744, 5850, 5880, 5896, 5888]
# [9851, 5932, 5808, 5795, 5804, 5674, 5790, 5723, 5773, 5930]
# [9954, 5748, 5810, 5860, 5778, 5730, 5767, 5883, 5731, 5827]
# [9882, 5758, 5760, 5803, 5863, 5767, 5781, 5748, 5854, 5877]
# [9917, 5890, 5649, 5858, 5843, 5737, 5881, 5794, 5775, 5753]
# [9939, 5923, 5729, 5833, 5792, 5688, 5809, 5753, 5724, 5911]
# [9965, 5825, 5919, 5792, 5728, 5736, 5806, 5861, 5741, 5736]
# [10033, 5766, 5863, 5642, 5735, 5827, 5983, 5682, 5745, 5838]
# [9890, 6096, 5724, 5735, 5832, 5752, 5702, 5725, 5829, 5833]
# [9837, 5771, 5801, 5836, 5810, 5713, 5686, 5948, 5874, 5846]
# [9889, 5724, 5888, 5791, 5822, 5835, 5838, 5744, 5783, 5812]
# [9872, 5663, 5876, 5822, 5907, 5759, 5723, 5753, 5808, 5947]
# [9940, 5854, 5754, 5887, 5682, 5616, 5843, 5867, 5772, 5920]
# [9820, 5894, 5859, 5820, 5894, 5893, 5672, 5726, 5789, 5772]
# [10029, 5690, 5852, 5860, 5751, 5831, 5796, 5851, 5780, 5707]
# [1308, 658, 687, 684, 694, 636, 695, 685, 672, 693]
# [5154, 2884, 2973, 2972, 2901, 2993, 2980, 2941, 2961, 2923]#
# [9832, 5827, 5799, 5721, 5774, 5956, 5762, 5680, 5862, 5858]


numbers = input("").split(" ")
numbers = [int(i) for i in numbers]
sum = 0
for i in range(0, len(numbers)):
    sum += numbers[i]

answer = 0
runs = 0


# 1st pass at 1k
while len(str(answer)) < sum:
    answer = math.factorial(runs)
    runs += 1000

# For some reason it always overshoots by 1k on high values
if sum > 20000:
    runs -= 1000

# 2nd pass at 100
while len(str(answer)) > sum:
    answer = math.factorial(runs)
    runs -= 100
    if runs < 0:
        runs = 0
        break

# 3rd pass at 10
while len(str(answer)) < sum:
    answer = math.factorial(runs)
    runs += 10


# Final pass
while True:
    answer = math.factorial(runs)
    if len(str(answer)) == sum:
        numbersInAnswer = [0,0,0,0,0,0,0,0,0,0]

        for value in str(answer):
            numbersInAnswer[int(value)] += 1
        
        if numbersInAnswer == numbers:
            print(runs)
            break

    # Move the delta up and down to find the exact number
    if len(str(answer)) > sum:
        runs -= 1
    else:
        runs += 1

    # Add randomness to fix getting stuck in "ditches"
    randNumber = random.randint(-10, 10)
    while runs + randNumber < 0:
        randNumber = random.randint(-10, 10)
    runs += randNumber
    
# Printing the time taken in seconds
# print(time.process_time())

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
0 0 1 0 0 0 0 0 0 0

correct output
2

user output
2

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
0 0 0 0 0 0 1 0 0 0

correct output
3

user output
3

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
0 0 1 0 1 0 0 0 0 0

correct output
4

user output
4

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
2 0 1 1 0 0 1 0 2 0

correct output
10

user output
10

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
9 3 1 1 2 2 3 1 6 1

correct output
27

user output
27

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 4 3 4 3 2 2 4 3 7

correct output
36

user output
36

Test 7

Group: 2, 3

Verdict: ACCEPTED

input
71 53 36 30 25 29 42 24 34 29

correct output
199

user output
199

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
71 33 46 38 27 45 36 21 35 35

correct output
205

user output
205

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
93 38 35 26 43 54 38 25 41 34

correct output
222

user output
222

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
100 33 33 45 36 43 38 54 56 36

correct output
242

user output
242

Test 11

Group: 3

Verdict:

input
3419 1797 1845 1849 1879 1791 ...

correct output
5959

user output
(empty)

Test 12

Group: 3

Verdict:

input
4776 2695 2709 2781 2616 2753 ...

correct output
8391

user output
(empty)

Test 13

Group: 3

Verdict:

input
20097 12282 12229 12214 12406 ...

correct output
32001

user output
(empty)

Test 14

Group: 3

Verdict:

input
47934 29918 29878 29713 29984 ...

correct output
71718

user output
(empty)

Test 15

Group: 3

Verdict:

input
84691 54156 54277 54533 54296 ...

correct output
123123

user output
(empty)

Test 16

Group: 3

Verdict:

input
99098 63339 63878 64182 63904 ...

correct output
142663

user output
(empty)