Submission #17964139


Source Code Expand

Copy
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(A):
    K = len(A)
    a = np.sum(A % 3 == 1)
    b = np.sum(A % 3 == 2)
    S = np.sum(A) % 3
    best = K
    for i in range(a + 1):
        for j in range(b + 1):
            if (S - i - 2 * j) % 3 == 0:
                best = min(best, i + j)
    if best == K:
        return -1
    else:
        return best

N = np.array(list(read().rstrip()), np.int64) - ord('0')

print(main(N))

Submission Info

Submission Time
Task C - To 3
User maspy
Language Python (3.8.2)
Score 300
Code Size 556 Byte
Status AC
Exec Time 111 ms
Memory 27276 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 27
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All all_00.txt, all_01.txt, all_02.txt, all_03.txt, all_04.txt, all_05.txt, all_06.txt, all_07.txt, all_08.txt, all_09.txt, all_10.txt, all_11.txt, all_12.txt, all_13.txt, all_14.txt, all_15.txt, all_16.txt, handmade_00.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
all_00.txt AC 111 ms 26928 KB
all_01.txt AC 107 ms 27248 KB
all_02.txt AC 105 ms 27020 KB
all_03.txt AC 103 ms 26924 KB
all_04.txt AC 106 ms 27064 KB
all_05.txt AC 101 ms 26932 KB
all_06.txt AC 105 ms 27064 KB
all_07.txt AC 105 ms 27112 KB
all_08.txt AC 104 ms 27024 KB
all_09.txt AC 105 ms 27068 KB
all_10.txt AC 103 ms 26680 KB
all_11.txt AC 103 ms 26992 KB
all_12.txt AC 105 ms 27012 KB
all_13.txt AC 102 ms 27060 KB
all_14.txt AC 103 ms 27064 KB
all_15.txt AC 105 ms 27276 KB
all_16.txt AC 105 ms 27028 KB
handmade_00.txt AC 105 ms 26960 KB
random_00.txt AC 108 ms 26808 KB
random_01.txt AC 105 ms 26988 KB
random_02.txt AC 102 ms 27016 KB
random_03.txt AC 107 ms 27032 KB
random_04.txt AC 106 ms 27028 KB
sample_01.txt AC 106 ms 27020 KB
sample_02.txt AC 103 ms 27036 KB
sample_03.txt AC 104 ms 27256 KB
sample_04.txt AC 102 ms 26712 KB