Problem:


Score : 300 points

Problem Statement

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

2 \leq K \leq N \leq 100000

A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.

In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4



Sample input:
4 3
2 3 1 4


Sample output:
2

Submission status: Wrong Answer

Solution code:
import numpy as np
#import pdb

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
pos = np.argmin(A)

left = pos
right = N - pos - 1

st_list = [x for x in range(max(0, pos - K + 1), min(pos + 1, N))]

cnt = np.inf
for st in st_list:
    ed = st + K - 1
    left = st
    right = N - ed - 1
    left_count = np.ceil(left / (K-1))
    right_count = np.ceil(right / (K-1))
    if cnt > (left_count + right_count):
        cnt = left_count + right_count

print(cnt.astype(np.uint64))

Submission status: Wrong Answer

Solution code:
import numpy as np
#import pdb

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
pos = np.argmin(A)

left = pos
right = N - pos - 1

st_list = [x for x in range(max(0, pos - K + 1), min(pos + 1, N))]

cnt = np.inf
for st in st_list:
    ed = st + K - 1
    left = st
    right = N - ed - 1
    left_count = np.ceil(left / (K-1))
    right_count = np.ceil(right / (K-1))
    if cnt > (left_count + right_count):
        cnt = left_count + right_count

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
#import pdb

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
pos = np.argmin(A)

left = pos
right = N - pos - 1

st_list = [x for x in range(pos - K + 1, pos + 1)]

cnt = np.inf
for st in st_list:
    ed = st + K - 1
    left = st
    right = N - ed - 1
    left_count = np.ceil(left / (K-1))
    right_count = np.ceil(right / (K-1))
    if cnt > (left_count + right_count):
        cnt = left_count + right_count

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
#import pdb

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
pos = np.argmin(A)

"""
pos = np.where(A == A.min())[0]
#pdb.set_trace()

tmp = -1
ans = 0
for pos_one in pos:
    ans += np.ceil((pos_one - tmp - 1) / (K-1))
    tmp = pos_one

ans += np.ceil((N - tmp - 1) / (K-1))
print(ans.astype(np.uint64))
"""

left = pos
right = N - pos - 1

if N <= K:
    print(1)
elif right + 1 <= K and left + 1 <= K:
    print(2)
elif right + 1 <= K:
    left -= K - (right + 1)
    left_count = np.ceil(left / (K-1))
    right_count = np.ceil(right / (K-1))
    print((left_count + right_count).astype(np.uint64))
elif left + 1 <= K:
    right -= K - (left + 1)
    left_count = np.ceil(left / (K-1))
    right_count = np.ceil(right / (K-1))
    print((left_count + right_count).astype(np.uint64))
else:
    left_count = np.ceil(left / (K-1))
    hamide = K - (left % (K - 1)) - 1
    right = right - hamide
    right_count = np.ceil(right / (K-1))
    print((left_count + right_count).astype(np.uint64))

Submission status: Wrong Answer

Solution code:
import numpy as np
#import pdb

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
pos = np.argmin(A)

"""
pos = np.where(A == A.min())[0]
#pdb.set_trace()

tmp = -1
ans = 0
for pos_one in pos:
    ans += np.ceil((pos_one - tmp - 1) / (K-1))
    tmp = pos_one

ans += np.ceil((N - tmp - 1) / (K-1))
print(ans.astype(np.uint64))
"""

left = pos
right = N - pos - 1

if N <= K:
    print(1)
elif right + 1 <= K and left + 1 <= K:
    print(2)
elif right + 1 <= K:
    left -= K - (right + 1)
    left_count = np.ceil(left / (K-1))
    right_count = np.ceil(right / (K-1))
    print((left_count + right_count).astype(np.uint64))
elif left + 1 <= K:
    right -= K - (left + 1)
    left_count = np.ceil(left / (K-1))
    right_count = np.ceil(right / (K-1))
    print((left_count + right_count).astype(np.uint64))
else:
    left_count = np.ceil(left / (K-1))
    right_count = np.ceil(right / (K-1))
    print((left_count + right_count).astype(np.uint64))

Submission status: Wrong Answer

Solution code:
import numpy as np
#import pdb

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
pos = np.argmin(A)

"""
pos = np.where(A == A.min())[0]
#pdb.set_trace()

tmp = -1
ans = 0
for pos_one in pos:
    #print(np.ceil((pos_one - tmp - 1) / (K-1)))
    ans += np.ceil((pos_one - tmp - 1) / (K-1))
    tmp = pos_one

#print(np.ceil((N - tmp - 1) / (K-1)))
ans += np.ceil((N - tmp - 1) / (K-1))
print(ans.astype(np.uint64))
"""

left = pos
right = N - pos - 1

left_count = np.ceil(left / (K-1))
right_count = np.ceil(right / (K-1))
print((left_count + right_count).astype(np.uint64))

Submission status: Wrong Answer

Solution code:
import numpy as np
#import pdb

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
pos = np.where(A == A.min())[0]
#pdb.set_trace()

tmp = -1
ans = 0
for pos_one in pos:
    #print(np.ceil((pos_one - tmp - 1) / (K-1)))
    ans += np.ceil((pos_one - tmp - 1) / (K-1))
    tmp = pos_one

#print(np.ceil((N - tmp - 1) / (K-1)))
ans += np.ceil((N - tmp - 1) / (K-1))
"""
left = pos
right = N - pos - 1

left_count = np.ceil(left / (K-1))
right_count = np.ceil(right / (K-1))
print((left_count + right_count).astype(np.uint64))
"""
print(ans.astype(np.uint64))

Submission status: Wrong Answer

Solution code:
import numpy as np
#import pdb

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)
pos = np.where(A == A.min())[0]
#pdb.set_trace()

tmp = 0
ans = 0
for pos_one in pos:
    ans += np.ceil((pos_one - tmp - 1) / (K-1))
    tmp = pos_one

ans += np.ceil((N - tmp - 1) / (K-1))
"""
left = pos
right = N - pos - 1

left_count = np.ceil(left / (K-1))
right_count = np.ceil(right / (K-1))
print((left_count + right_count).astype(np.uint64))
"""
print(ans.astype(np.uint64))

Submission status: Wrong Answer

Solution code:
import numpy as np

tmp = list(map(int, input().strip().split(' ')))
N = tmp[0]
K = tmp[1]
A = list(map(int, input().strip().split(' ')))

A = np.asarray(A)

pos = np.argmin(A)

left = pos
right = N - pos - 1

left_count = np.ceil(left / (K-1))
right_count = np.ceil(right / (K-1))
print((left_count + right_count).astype(np.uint64))

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    N, K = [int(_) for _ in input().split()]
    A = [int(_) for _ in input().split()]

    min_num_idx = A.index(min(A))

    ans = 0

    left_idx = min_num_idx
    while left_idx > 0:
        ans += 1
        left_idx -= (K - 1)

    right_idx = min_num_idx
    while right_idx < (N - 1):
        ans += 1
        right_idx += (K - 1)

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = [int(i) for i in list(input().split())]

min_point = np.argmin(A)
before = int(np.ceil(min_point/(K-1)))
after_length = N - min_point - 1
after = int(np.ceil(after_length/(K-1)))
print(int(before+after))

Submission status: Wrong Answer

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
k = int(arr_data[0][1])

arr = [int(x) for x in arr_data[1]]
mindata = min(arr)
arr_replace = [mindata for x in range(k)]

cnt = 0

for i in range(0,len(arr),k+1):
    
    if not(all(x == mindata for x in arr[i:i + k])):
        cnt += 1
        arr[i:i + k] = arr_replace
    
    if not(all(x == mindata for x in arr[i + k-1:i + k-1 + k])):
        cnt += 1
        arr[i + k-1:i + k-1 + k] = arr_replace
    
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(input().split())
A = [int(i) for i in A]
argmin_point = np.argmin(A)
forward = N - argmin_point- 1
forward_cnt = int(np.trunc((forward / (K - 1)) + .5))
backward_cnt = int(np.trunc(((argmin_point - 1) / (K - 1)) + 0.5))

print(forward_cnt + backward_cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(input().split())
A = [int(i) for i in A]
argmin_point = np.argmin(A)
forward = N - argmin_point- 1
forward_cnt = int(round((forward / (K - 1)) + 0.499999999))
backward_cnt = int(round(((argmin_point - 1) / (K - 1)) + 0.499999999))

print(forward_cnt + backward_cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(input().split())
A = [int(i) for i in A]
argmin_point = np.argmin(A)
forward = N - argmin_point- 1
forward_cnt = int(round((forward / (K - 1)) + 0.49999999999999999))
backward_cnt = int(round(((argmin_point - 1) / (K - 1)) + 0.49999999999999999))

print(forward_cnt + backward_cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(input().split())
A = [int(i) for i in A]
argmin_point = np.argmin(A)
forward = N - argmin_point- 1
forward_cnt = int(round((forward / (K - 1)) + 0.5))
backward_cnt = int(round(((argmin_point - 1) / (K - 1)) + 0.5))

print(forward_cnt + backward_cnt)

Submission status: Wrong Answer

Solution code:
from math import ceil

n, k = map(int, input().split())
A = list(map(int, input().split()))

index_min = A.index(1)

ans = ceil(index_min / (k - 1))
ans += ceil((len(A) - index_min - 1) / (k - 1))

print(ans)

Submission status: Wrong Answer

Solution code:
# your code goes here

N,K = map(int,input().split())
li = list(map(int,input().split()))	
if N == K:
	print(1)
	quit()
i = 1
N = N-K

while N >= K:
	N = N - K +1
	i = i + 1

print()

Submission status: Wrong Answer

Solution code:
# your code goes here

N,K = map(int,input().split())
li = list(map(int,input().split()))	

i = 1
N = N-K

while N >= K:
	N = N - K +1
	i = i + 1

print(i + 1)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = input().split(" ")
n = int(n)
k = int(k)
a = input()
print(n // (k - 1))

Submission status: Wrong Answer

Solution code:
from math import ceil
n, k = map(int, input().split())
min_idx = list(map(int, input().split())).index(1)
min_count = n
left = min_idx - k + 1
if left < 0: left = 0
for i in [left, min_idx]:
    s_idx, l_idx = i, i + k - 1
    if s_idx < 0: s_idx = 0
    if l_idx > n - 1: l_idx = n - 1
    count = ceil(s_idx / (k - 1)) + ceil((n - 1 - l_idx) / (k - 1)) + 1
    if min_count > count: min_count = count
print(min_count)

Submission status: Wrong Answer

Solution code:
from math import ceil
n, k = map(int, input().split())
min_idx = list(map(int, input().split())).index(1)
min_count = n
left = min_idx - k + 1
if left < 0: left = 0
for i in [left, min_idx]:
    s_idx = l_idx = min_idx
    if s_idx > 0: s_idx = i
    if l_idx < n: l_idx = i + k - 1
    count = ceil(s_idx / (k - 1)) + ceil((n - 1 - l_idx) / (k - 1)) + 1
    if min_count > count: min_count = count
print(min_count)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
min_idx = a.index(1)
min_count = n
left = min_idx - k + 1
if left < 0: left = 0
for i in [left, min_idx]:
    s_idx = l_idx = min_idx
    if s_idx > 0: s_idx = i
    if l_idx < n: l_idx = i + k - 1
    count = 1
    while s_idx > 0:
        s_idx -= k - 1
        count += 1
    while l_idx < n - 1:
        l_idx += k - 1
        count += 1
    if min_count > count: min_count = count
print(min_count)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
min_idx = a.index(1)
min_count = n
left = min_idx - k + 1
right = min_idx + k - 1
if left < 0: left = 0
if right > n - 1: right = n - 1
for i in [left, right]:
    s_idx = l_idx = min_idx
    if s_idx > 0: s_idx = i
    if l_idx < n: l_idx = i + 2
    count = 1
    while s_idx > 0:
        s_idx -= 2
        count += 1
    while l_idx < n - 1:
        l_idx += 2
        count += 1
    if min_count > count: min_count = count
print(min_count)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
min_idx = a.index(1)
min_count = n
for i in range(min_idx-2, min_idx+3):
    if 0 <= i < n - 2:
        s_idx = l_idx = min_idx
        if s_idx > 0: s_idx = i
        if l_idx < n: l_idx = i + 2
        count = 1
        while s_idx > 0:
            s_idx -= 2
            count += 1
        while l_idx < n - 1:
            l_idx += 2
            count += 1
        if min_count > count: min_count = count
print(min_count)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
min_idx = a.index(1)
min_count = n
for i in range(min_idx-2, min_idx+3):
    if 0 <= i < n - 2:
        s_idx = l_idx = min_idx
        if s_idx > 0: s_idx = i
        if l_idx < n: l_idx = i + 2
        print("Start: {}..{}".format(s_idx, l_idx))
        count = 1
        while s_idx > 0:
            s_idx -= 2
            count += 1
            print("s_idx: {}..{}".format(s_idx, l_idx))
        while l_idx < n - 1:
            l_idx += 2
            count += 1
            print("l_idx: {}..{}".format(s_idx, l_idx))
        if min_count > count: min_count = count
print(min_count)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

i = A.index(1)
if i == 0:
    r = ceil((N-1) / (K-1))
else:
    # L
    l = ceil(i/(K-1))
    # R
    r =ceil((N-1-i)/(K-1))
    r+=l

print(r)

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

i = A.index(1)
if i == 0:
    r = int((N-1) / (K-1))
else:
    # L
    l = int(i/(K-1))
    # R
    r = int((N-1-i)/(K-1)) +1
    r+=l

print(r)

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=map(int,input().split())
c=0
for i in a:
    c+=1
    if(i==1):
        s=c-1
        e=n-c
        break
if(s==0):print(math.ceil(e/(k-1)))
elif(e==0):print(math.ceil(s/(k-1)))
else:print(math.ceil(s/(k-1))+math.ceil(e/(k-1)))

Submission status: Wrong Answer

Solution code:
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
print N/K+(0 if N%K == 0 else 1)

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=map(int,input().split())
c=0
for i in a:
    c+=1
    if(i==1):
        s=c-1
        e=n-c
print(math.ceil(s/(k-1))+math.ceil(e/(k-1)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = [int(_) for _ in input().split()]

if k == n:
    print(1)
    exit()

i = a.index(1)
l, r = i, i
cnt = 0

# left
while l > 0:
    l -= k - 1
    cnt += 1
# right
while r < n - 1:
    r += k - 1
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = [int(_) for _ in input().split()]

i = a.index(1)
l, r = i, i
cnt = 0

# left
while l > 0:
    l -= k - 1
    cnt += 1
# right
while r < n - 1:
    r += k - 1
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

i = A.index(1)

back = i
forword = N - i - 1

ans = math.ceil(back / (K - 1)) + math.ceil(forword / (K - 1))

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
nums = list(input().split(" "))
s = nums.index("1")
l = int((s+1) / (K-1))
r = int((N-s) / (K-1))
print(r + l)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
nums = list(input().split(" "))
#print(nums.index("1"))
a = nums.index("1")
print(int((a+1) / (K-1)) + int((N-a) / (K-1)))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
nums = list(input().split(" "))
a = nums.index("1")
l = (a+1) / (K-1)
r = (N-a) / (K-1)
print(l + r)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
nums = list(input().split(" "))
a = nums.index("1")
print(int((a+1) / 2) + int((N-a) / 2))

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, raw_input().split(' '))
    A = map(int, raw_input().split(' '))

    position_1 = A.index(1)
    if position_1 <= K or N-K <= position_1:
        if (N-K) % (K-1) > 0:
            print 1 + (N-K)/(K-1) + 1
        else:
            print 1 + (N-K)/(K-1)
    else:
        if (N-K) % (K-1) > 0:
            print 1 + (N-K)/(K-1) + 2
        else:
            print 1 + (N-K)/(K-1) + 1

main()

Submission status: Wrong Answer

Solution code:
import math
(n,k) = input().split(" ")
n=int(n)
k=int(k)
arr = input().split(" ")

idx = arr.index("1")
if idx < k or n-idx-1 < k:
    num=math.ceil((n-k)/(k-1))+1
else:
    num1 = math.ceil(idx+1/k)
    num = num1+math.ceil((n-num1*k-1-k)/(k-1))+1
print(num)

Submission status: Wrong Answer

Solution code:
import math
(n,k) = input().split(" ")
n=int(n)
k=int(k)
arr = input().split(" ")

idx = arr.index("1")
if idx < k or n-idx-1 < k:
    num=math.ceil((n-k)/(k-1))+1
else:
    num=math.ceil((idx+1-k)/(k-1))+1 + math.ceil((n-idx-k)/(k-1))+1
print(num)

Submission status: Wrong Answer

Solution code:
N,K = [ int(c) for c in input().split(" ")]

A = [ int(c) for c in input().split(' ')]

stone = A.index(min(A))

downs = stone
ups = len(A) - stone - 1

d = K-1
answer = (downs+d-1)//d + (ups+d-1)//d

print(answer)

Submission status: Wrong Answer

Solution code:
N,K = [ int(c) for c in input().split(" ")]

A = [ int(c) for c in input().split(' ')]

stone = A.index(min(A))

downs = stone
ups = len(A) - stone +1

d = K-1
answer = ups//d + downs//d

print(answer)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    m = min(A)
    mi = A.index(m)
    if (N == K):
        print(1)
    else:
        c = mi // (K - 1)
        if mi % (K - 1) > 0: c += 1
        c += (N - mi - 1) // (K - 1)
        if (N - mi - 1) % (K - 1) > 0: c += 1
        print(c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    m = min(A)
    mi = A.index(m)
    c = 0
    c += (N - 1) // (K - 1)
    if mi % (K - 1) > 0: c += 1
    if (N - mi - 1) % (K - 1) > 0: c += 1
    print(c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    m = min(A)
    mi = A.index(m)
    c = 0
    c += mi // (K - 1)
    c += (N - mi - 1) // (K - 1)
    if (N - 1) % (K - 1) > 0: c += 1
    print(c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

n, k = list(map(int, input().split()))
array = list(map(int, input().split()))

minimum = min(array)
dist = 0
dists = []

for a in array:
    if a != minimum:
        dist += 1
    else:
        dists.append(dist)
        dist = 0
dists.append(dist)

ans = 0
for d in dists:
    ans += math.ceil(d / (k-1))

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    m = min(A)
    mi = A.index(m)
    c = 0
    c += mi // (K - 1)
    if mi % (K - 1) > 0: c += 1
    c += (N - mi - 1) // (K - 1)
    if (N - mi - 1) % (K - 1) > 0: c += 1
    print(c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
print((n - 1) // (m - 1) + (n - 1) % (m - 1))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
input()

print(round((N-1)/(K-1)))

Submission status: Wrong Answer

Solution code:
import math
n, m = map(int, input().split())
s = map(int, input().split())
print(math.ceil(m-1/2))

Submission status: Wrong Answer

Solution code:
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

j=l_i.index(1)
j

if N==K:
    print(1)
else:
    a=-(-j//(K-1)) + (-(-(N-1-j)//(K-1)))
    print(a)

Submission status: Wrong Answer

Solution code:
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

j=l_i.index(1)
j

if N==K:
    print(1)
else:
    a=1+j//(K-1)+1+(N-1-j)//(K-1)
    print(a)

Submission status: Wrong Answer

Solution code:
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

j=l_i.index(1)
j

if N==K:
    print(1)
else:
    a=1+j//(K-1)+1+(N-1-j)//K-1
    print(a)

Submission status: Wrong Answer

Solution code:
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

if N==K:
    print(1)
else:
    b=(N-K)//(K-1) +2
    print(b)

Submission status: Wrong Answer

Solution code:
nk=input().split()
l=input().split()

nk_i=[int(s) for s in nk]
N=nk_i[0]
K=nk_i[1]

l_i=[int(s) for s in l]

if N==K:
    print('1')
else:
    a=N//K +1
    print(a)

Submission status: Wrong Answer

Solution code:
N,K=[int(i) for i in input().split()]
A=list(map(int,input().split()))

j=A.index(1)
print(-((-j)//(K-1))-(-(N-j-1))//(K-1))

Submission status: Wrong Answer

Solution code:
N,K=[int(i) for i in input().split()]
A=list(map(int,input().split()))

j=A.index(1)
print(-(-j)//(K-1)-(-(N-j-1))//(K-1))

Submission status: Wrong Answer

Solution code:
n, k = tuple(int(x) for x in input().split())
nums = [int(x) for x in input().split()]

anchor = nums.index(min(nums))
num_ba = anchor
num_aa = n - (anchor + 1)

rem_ba = num_ba % (k - 1)
rem_aa = num_aa % (k - 1)

result = num_ba // (k - 1) + (0 if rem_ba == 0 else 1) + \
         num_aa // (k - 1) + (0 if rem_aa == 0 else 1)
if rem_ba != 0 and \
   rem_aa != 0 and \
   rem_ba + rem_aa % k != 0:
      result -= 1

print(result)

Submission status: Wrong Answer

Solution code:
n, k = tuple(int(x) for x in input().split())
nums = [int(x) for x in input().split()]

anchor = nums.index(min(nums))
num_ba = anchor
num_aa = n - (anchor + 1)

result = num_ba // (k - 1) + (0 if num_ba % (k - 1) == 0 else 1) + \
         num_aa // (k - 1) + (0 if num_aa % (k - 1) == 0 else 1) - \
  		 (0 if (num_ba + num_aa) % k == 0 else 1)
print(result)

Submission status: Wrong Answer

Solution code:
n, k = tuple(int(x) for x in input().split())
nums = [int(x) for x in input().split()]

anchor = nums.index(max(nums))
num_ba = anchor
num_aa = n - (anchor + 1)

result = num_ba // (k - 1) + (0 if num_ba % (k - 1) == 0 else 1) + \
         num_aa // (k - 1) + (0 if num_aa % (k - 1) == 0 else 1)
print(result)

Submission status: Wrong Answer

Solution code:
import math


n, k = input().split(' ')
n, k = int(n), int(k)
a = [int(x) for x in input().split(' ')]

one = a.index(1)
l, r = one, len(a) - one - 1

print(math.ceil(l / 2) + math.ceil(r / 2))

Submission status: Wrong Answer

Solution code:
import math


n, k = input().split(' ')
n, k = int(n), int(k)
a = [int(x) for x in input().split(' ')]
print(int(math.ceil(n / (k - 1))))

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split(' ')))
l = list(map(int,input().split(' ')))
piv = l.index(1)
ans = N
if N ==K:
    print(1)
else:
    fpiv=piv
    bpiv=piv
    count =0
    for j in range(K):
        while fpiv > 0:
            fpiv = fpiv -K-1-j
            count +=1
        while bpiv < N-1:
            bpiv = bpiv +K-1-j
            count +=1
        if count < ans:
            ans = count
    print(ans)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split(' ')))
l = list(map(int,input().split(' ')))
piv = l.index(1)
ans = 0
if N ==K:
    print(1)
else:
    fpiv=piv
    bpiv=piv
    while fpiv > 0:
        fpiv = fpiv -K+1
        ans +=1
    while bpiv < N-1:
        bpiv = bpiv +K-1
        ans +=1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split(' ')))
l = list(map(int,input().split(' ')))
piv = l.index(1)
ans = 0
if N ==K:
    print(1)
else:
    fpiv= piv
    bpiv=piv
    while fpiv !=0:
        if fpiv -K+1 >= 0:
            fpiv = fpiv -K+1
        else:
            fpiv = 0
        ans +=1
    while bpiv !=N-1:
        if bpiv +K-1 <= N-1:
            bpiv = bpiv +K-1
        else:
            bpiv = N-1
        ans +=1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split(' ')))
l = list(map(int,input().split(' ')))
piv = l.index(1)
ans = 0
if N ==K:
    print(1)
else:
    fpiv= piv
    bpiv=piv
    while 1:
        if fpiv -K+1 > 0:
            fpiv = fpiv -K+1
        else:
            fpiv = 0
        ans +=1
        if fpiv ==0:break
    while 1:
        if bpiv +K-1 < N-1:
            bpiv = bpiv +K-1
        else:
            bpiv = N-1
        ans +=1
        if bpiv == N-1:break
    print(ans)

Submission status: Wrong Answer

Solution code:
n,k=input().split()
n=int(n)
k=int(k)

if n==k:
	print(1)
elif n//(k-1)==1:
	print(2)
else:
	print(n//(k-1))

Submission status: Wrong Answer

Solution code:
n,k=input().split()
n=int(n)
k=int(k)

print(n//(k-1))

Submission status: Wrong Answer

Solution code:
import math

l = input().split()
n = l[0]
k = l[1]
l = input().split()

pr = l.index("1")
af = int(n)-pr-1

k = int(k) - 1

count = 0
count = math.ceil(pr/k) + math.ceil(af/k)

print(count)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
A=input()
if (N-1)%(K-1):
    print((N-1)//(K-1))
else:
    print((N-1)//(K-1)+1)

Submission status: Wrong Answer

Solution code:
import math
n, k = input().split()
n = int(n)
k = int(k)
aa = input().split()
aa = [int(a) for a in aa]
ans = 0

 
pos=[]

for i  in range(len(aa)):
   if n==k:
      print(1)
      break

   if aa[i] == 1:
      pos=i
      if pos<k:
         #print("ptA")
         pos=k-1
         ans+=1
         ans+= math.ceil((n-pos-1)/(k-1))
      elif pos>=(n-k):
         #print("ptB")
         ans+=1
         pos=n-k
         ans+=math.ceil( pos/(k-1))
      else:
         #print("ptC")
         ans+= math.ceil((n-pos-1)/(k-1))
         ans+=math.ceil( pos/(k-1))


      print(ans)
      break

Submission status: Wrong Answer

Solution code:
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))

I = A.index(1)

left = I
right = N - I - 1

print(math.ceil(left/(K-1)) + math.ceil(right/(K-1)))

Submission status: Wrong Answer

Solution code:
import math
a, b = map(int, input().split())
c = b - 1

d = a / c

print(math.ceil(d))

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = b - 1

d = a / c

print(d + 1)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = b - 1

d = a / c

print(d)

Submission status: Wrong Answer

Solution code:
import math
n, k = input().split()
n = int(n)
k = int(k)
aa = input().split()
aa = [int(a) for a in aa]
ans = 0

 
pos=[]

for i  in range(len(aa)):
   if n==k:
      print(1)
      break

   if aa[i] == 1:
      pos=i
      if pos<k:
         pos=k

      ans+= math.ceil((n-pos-1)/(k-1))
      #print(ans)
      if pos==k:
         ans+=1
      else:
         ans+=math.ceil( pos/(k-1))
      print(ans)
      break

Submission status: Wrong Answer

Solution code:
X = input().split()
N = int(X[0])
K = int(X[1])

A = input().split()
A.sort()

TH_num = 0
count = 0
while True:
    if TH_num < len(A) and TH_num == 0:
        TH_num = 3
        count += 1
    elif TH_num < len(A):
        TH_num += 2
        count += 1
    if TH_num >= len(A):
        print(count)
        break

Submission status: Wrong Answer

Solution code:
import math
n, k = input().split()
n = int(n)
k = int(k)
aa = input().split()
aa = [int(a) for a in aa]
ans = 0

 
pos=[]

for i  in range(len(aa)):
   if n==k:
      print(1)
      break
   if aa[i] == 1:
      pos=i
 
      ans+= math.ceil((n-pos-1)/(k-1))
 
      ans+=math.ceil( pos/(k-1))
      print(ans)
      break

Submission status: Wrong Answer

Solution code:
import math
n, k = input().split()
n = int(n)
k = int(k)
aa = input().split()
aa = [int(a) for a in aa]
ans = 0




pos=[]

for i  in range(len(aa)):
   if aa[i] == 1:
      pos=i

      ans+= math.ceil((n-pos-1)/(k-1))

      ans+=math.ceil( pos/(k-1))
      print(ans)
      break

Submission status: Wrong Answer

Solution code:
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(n, k, as1):
    if (n-1)%(k-1)==0:
        return (n-1)//(k-1)
    else:
        return round((n-1)/(k-1))

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_n, str_k] = line.split(' ')
    line = sys.stdin.readline().rstrip()
    as1 = line.split(' ')
    return (int(str_n), int(str_k), [int(a) for a in as1])

def main():
    n, k, as1 = readQuestion()
    answer = solve(n, k, as1)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
nums = list(map(int, input().split()))
index = nums.index(1)
print(ceil(index / (K - 1)) + ceil((N - index - 1) / (K - 1)))

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
nums = list(map(int, input().split()))
index = nums.index(1)
print(ceil(index / K) + ceil((N - index - 1) / K))