Submission #680237

# Submission time Handle Problem Language Result Execution time Memory
680237 2023-01-10T10:13:27 Z vjudge1 JJOOII 2 (JOI20_ho_t2) Python 3
0 / 100
16 ms 3028 KB
var1 = input()
n, k = int(var1.split(" ")[0]), int(var1.split(" ")[1])
s = input()


def delete_sides(s):
    while (len(s)>0) and (s[0] != "J") :
        s = s[1:]
    while (len(s)>0) and (s[-1] != "I"):
        s = s[:-1]
    return s

def check(n, k, s):
    ind = 0
    j_count, o_count, i_count = 0, 0, 0
    while (j_count < k) and (ind < len(s)):
        if s[ind] == "J":
            j_count += 1
        ind += 1
    while (o_count < k) and (ind < len(s)):
        if s[ind] == "O":
            o_count += 1
        ind += 1
    while (i_count < k) and (ind < len(s)):
        if s[ind] == "I":
            i_count += 1
        ind += 1
    if (j_count != k) or (o_count != k) or (i_count != k):
        return -1
    else:
        return len(s)-k*3


def count_j(s):
    count = 0
    for i in range(0, len(s)):
        if s[i] == "J":
            count += 1
    return count
    
def count_i(s):
    count = 0
    for i in range(0, len(s)):
        if s[i] == "I":
            count += 1
    return count


s = delete_sides(s)
num_j, num_i = count_j(s), count_i(s)
if (num_j-k < 0) or (num_i-k < 0):
    print(-1)
# print(s , " sss")

# print(num_j, num_i, "   j  i ")
min = 1000000000
if (num_j-k == 0) and (num_i-k != 0):
    print("alpha")
    for b in range(0, num_i-k):
        tries = check(n, k, s)
        # print(tries, "   tries")
        if (tries != -1) and (tries < min):
            min = tries
        s = s[:-1]
        while (len(s)>0) and (s[-1] != "I"):
            s = s[:-1]
elif (num_i-k == 0) and (num_j-k != 0):
    # print("beta")
    for a in range(0, num_j-k):
        tries = check(n, k, s)
        # print(tries, "   tries")
        if (tries != -1) and (tries < min):
            min = tries
        s = s[1:]
        while (len(s)>0) and (s[0] != "J") :
            s = s[1:]
        
else:
    # print("gamma")
    for a in range(0, num_j-k):
        s = s[1:]
        while (len(s)>0) and (s[0] != "J") :
            s = s[1:]
        for b in range(0, num_i-k):
            tries = check(n, k, s)
            # print(tries, "   tries")
            if (tries != -1) and (tries < min):
                min = tries
            s = s[:-1]
            while (len(s)>0) and (s[-1] != "I"):
                s = s[:-1]
if min == 1000000000:
    print(-1)
else:
    print(min)
# print(min, "  min")
        
        
# if check(n, k, s) == -1:
#     print(-1)
# else:
#     print(check(n, k, s))



# if check(n, k, s[1:-1]) == 1:
#     print(len(s)-2-k*3) 
# elif check(n, k, s[1:]) == 1:
#     print(0)
# elif check(n, k, s) == 1:
#     print(0)
# else: 
#     print(-1)

    
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -