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:

def main():
    n, k = [int(i.strip()) for i in input().split(' ')]
    s = [int(i.strip()) for i in input().split(' ')]

    if n == k:
        print(1)

    if n // k == 1:
        print(2)
    
    idx = s.index(1)
    m1, c1 = divmod(len(s[idx:]), k-1)
    if m1 == 0 and c1 > 0:
        m1 += 1
    m2, c2 = divmod(len(s[:idx])+1, k-1)
    if m2 == 0 and c2 > 0:
        m2 += 1

    print(m1+m2)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
data = map(int, input().split())
one_left = 0
if k == 2:
    print(n//(k-1)-1)
else:
    for i in data:
        if i != 1:
            one_left += 1
        else:
            break

    one_right = n - one_left - 1

    # 1の左右について考える
    left_amari = one_left % (k-1)
    left_cnt = math.ceil(one_left / (k-1))
    # print(left_amari)
    if left_amari != 0:
        one_right = one_right - left_amari

    right_cnt = math.ceil(one_right / (k-1))
    # print(one_left, one_right, left_cnt, right_cnt)
    print(left_cnt + right_cnt)

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
if k == 2:
    print(n-1)
elif k == n-1:
    print(2)
elif (n-k)%(k-1) == 1:
  	print(n//(k-1) + 1)
else:
    print(n//(k-1))

Submission status: Wrong Answer

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

min_position = A.index(1)
left = min_position
right = N - 1 - left
min_num = N

if (left >= K and right >= K):
    for k in range(K):
        left_num = max(0, left + k)
        right_num = min(0, right + K - 1 - k) 
        min_num = min(min_num, (left_num + 1) // (K - 1) + (right_num + 1) // (K - 1) + 2)
    print(min_num)
else:
    print((N - K + 1) // (K - 1) + 1)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(" "))
#A,B = input().split(" ")
A = list(map(int,input().split(" ")))
min = min(A)
i = A.index(min)
bot = i -int((M-1)*(i/(i+N-1-i)))
up = i + (M-1) - int((M-1)*(i/(i+N-1-i)))
cou = 1
while(up<N-1):
    up = up + M-1
    cou = cou + 1
while(bot>0):
    bot = bot - M-1
    cou = cou + 1

print(cou)

Submission status: Wrong Answer

Solution code:
def m():
    def solve(n,k):
        if n <= k:
            return 1
        tmp = 1
        tmp += (n-k) // (k-1)
        if (n-k) % (k-1) == 0:
            return tmp
        return tmp + 1

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    pos = a.index(1)
    ans = 1
    if pos <= k-1 or pos >= n - k:
        return solve(n,k)
    if k % 2 == 0:
        div = k // 2
        left = a[pos+(div-1):]
        right = a[:pos+(div-1)]
    else:
        div = k // 2
        left = a[pos+(div-1):]
        right = a[:pos+(div)]
    ans += solve(len(left), k) + solve(len(right),k)
    return ans
print(m())

Submission status: Wrong Answer

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

arr = map(int,raw_input().split())

ind = arr.index(1)

ans = 1

t = 0
while ind + k/2 + (k-1)*(t+1) < n:
	ans += 1
	t += 1

if ind + (k-1)/2 + (k-1)*t < n-1:
	ans += 1

t = 0

while ind - k/2 + (k-1) * (t-1) > -1:
	ans += 1
	t -= 1

if ind - k/2 + (k-1) * t > 0:
	ans += 1

print ans

Submission status: Wrong Answer

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

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

min_idx = A.index(min(A))

# print("N: {}\nK: {}\nA: {}\nmin_idx: {}".format(N,K,A,min_idx))

if N <= K:
    print(1)
else:
    k = K - 1 
    rtn = 0 
    idx = min_idx 
    while(idx < N - 1): 
        idx += k 
        rtn += 1 

    right_margin = K - (idx - N)
    idx = min_idx 
    while idx > 0:
        idx -= k 
        rtn += 1

    left_margin = -1 * idx 

    if right_margin + left_margin == K and K+1!=N:
        rtn -= 1

    print(rtn)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
import math
m = a.index(1)+1
print(math.ceil(max(0, m-2) / (k-1)) + math.ceil((n-m) / (k-1)))

Submission status: Wrong Answer

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

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

min_A = min(A)


ind1 = A.index(1)
len1 = N -ind1
len2 = ind1 + 1

r1= 0
if (len1-1)%(K-1) != 0:
    r1 = 1

r2= 0
if (len2-1)%(K-1) != 0:
    r2 = 1
d = 0



ans1 = (len1-1)//(K-1)+r1 + (len2-1)//(K-1)+r2

ans=[]
ans.append(ans1)
for i in range(1, K):
    ans2 = 0
    r3= 0
    if (len1-i-1)%(K-1) != 0:
        r3 = 1

    r4= 0
    if (len2-i-1)%(K-1) != 0:
        r4 = 1
    ans2 = (len1-i-1)//(K-1)+r3 + (len2-((K-1)-i)-1)//(K-1)+r4 + 1
    ans.append(ans2)


print(min(ans))

Submission status: Wrong Answer

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

A = [i for i in input().split()]

if N == K:
    print(1)

elif K == 2:
    print(N - 1)

elif N % (K - 1) <= K:
    print (int(N / (K - 1)))

else:
    print(int(N / (K -1) + 1))

Submission status: Wrong Answer

Solution code:
n,k = input().split(' ')
n,k = int(n),int(k)
p = list(input())
ans = 0
a,b = len(p[: k-1]),len(p[k:])

if n <= k:
    ans = 1
elif min(p[: k-1]) < min(p[k:]):
    while n > 0:
        n = n - k + 1
        ans += 1
else:
    idx = p.index(min(p[k:]))
    if idx + 1 < len(p) - k:        
        while n > 0:
        	n = n - k + 1
        	ans += 1
    else:
        if a < b:
            a = a - n + 1
            while a > 0:
                a = a - n + 1
                ans += 1
            while b > 0:
                b = b - n + 1
                ans += 1
        else:
            b = b - n + 1
            while a > 0:
                a = a - n + 1
                ans += 1
            while b > 0:
                b = b - n + 1
                ans += 1
      
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
m = 0
if a[0] == 1 or a[1]==1 or a[2]==1:
    for i in range(n-2):
        if a[i] == a[i+1] == a[i+2] or a[i] == a[i+1]:
            if a[i+2] == a[n-1]:
                a[i] = min(a[i],a[i+1],a[i+2])
                a[i+1] = min(a[i],a[i+1],a[i+2])
                a[i+2] = min(a[i],a[i+1],a[i+2])
                ans+= 1
            else:
                continue

        else:
            a[i] = min(a[i],a[i+1],a[i+2])
            a[i+1] = min(a[i],a[i+1],a[i+2])
            a[i+2] = min(a[i],a[i+1],a[i+2])
            ans+= 1
else:
    for i in range(n):
        if a[i]==1:
            m = i
            break
    for i in range(m,n-2):
        if a[i] == a[i+1] == a[i+2] or a[i] == a[i+1]:
            if a[i+2] == a[n-1]:
                a[i] = min(a[i],a[i+1],a[i+2])
                a[i+1] = min(a[i],a[i+1],a[i+2])
                a[i+2] = min(a[i],a[i+1],a[i+2])
                ans+= 1
            else:
                continue
        else:
            a[i] = min(a[i],a[i+1],a[i+2])
            a[i+1] = min(a[i],a[i+1],a[i+2])
            a[i+2] = min(a[i],a[i+1],a[i+2])
            ans+= 1
    for i in reversed(range(0,m+1)):
        if a[i] == a[i-1] == a[i-2] or a[i] == a[i-1]:
            if a[i-2] == a[0]:
                a[i] = min(a[i],a[i-1],a[i-2])
                a[i-1] = min(a[i],a[i-1],a[i-2])
                a[i-2] = min(a[i],a[i-1],a[i-2])
                ans+= 1
                break
            else:
                continue
        else:
            a[i] = min(a[i],a[i-1],a[i-2])
            a[i-1] = min(a[i],a[i-1],a[i-2])
            a[i-2] = min(a[i],a[i-1],a[i-2])
            ans+= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N,K = map(int, input().split())
lis = [int(i) for i in input().split()]
if N == 1:
  print(0)
  sys.exit()
if N<=K:
  print(1)
  sys.exit()
ind = lis.index(1)+1
pre = ind-1-1
pos = N-ind-1
if pre%(K-1)==0:
  a = pre//(K-1)
else:
  a = pre//(K-1)+1
if pos%(K-1)==0:
  b = pos//(K-1)
else:
  b = pos//(K-1)+1
print(1+a+b)

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
if k == 2:
    print(n-1)
elif k == n-1:
    print(2)
elif (n-k)%(k-1) != 0:
  	print(n//(k-1) + 1)
else:
    print(n//(k-1))

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
minIndex = A.index(min(A))

if K == len(A):
    print(1)
elif K == 2:
    print(len(A)-1)
else:
    cnt1 = math.ceil((minIndex+1)/K)
    cnt2 = math.ceil((len(A)-minIndex)/(K))
    if minIndex == 0:
        cnt1 = 0
    elif minIndex == len(A)-1:
        cnt2 = 0
    print(cnt1 + cnt2)

Submission status: Wrong Answer

Solution code:
# coding=utf-8

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

ctr = 0
if N <= K:
    print(1)
else:
    msr = number_list.index(1)
    if msr == 0 or msr == N-1:
        N = N - K
        print(N//(K-1) + 1)
    else:
        if msr <= K:
            ctr += 1
            right_rest = K - msr
        else:
            left_block = (msr-K)//(K-1) + 1
            right_rest = (msr-K) % (K-1)
            ctr += left_block
        right_all = N - msr
        right_all -= right_rest

        if right_all % (K-1) == 0:
            ctr += right_all // (K-1)
        else:
            ctr += right_all//(K-1)+1
        print(ctr)

Submission status: Wrong Answer

Solution code:
# C
import math, sys
n, k = map(int, input().split())
a = list(map(int, input().split()))
if n==k:
    print(1)
    sys.exit()

one = -1  # idx of '1'
for i in range(n):
    if a[i]==1: one = i
               
left = math.ceil(one/(k-1))
right = math.ceil((n-one-1)/(k-1))

print(int(left+right))

Submission status: Wrong Answer

Solution code:
from sys import stdin

N, K = [int (x) for x in stdin.readline().rstrip().split()]
A = [int (x) for x in stdin.readline().rstrip().split()]

front = 0
tail = 0
count = 0

for i in range(N):
    if A[i] == 1:
        break
    else:
        front += 1
tail = N - (front + 1)

count += (front + (K-2))//(K-1)
count += (tail + (K-2))//(K-1)

if front == K - 2 or tail == N - 2 :
    count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
index1=a.index(1)
if k>=index1+1 or n-(index1+1)<=k:
    print(round((len(a)-1)/(k-1)))
else:
    ans=float("inf")
    for i in range(k):
        ans=min(ans,1+round((index1+1-k-i)/k)+round((n-(index1+1)+i)/k))
    print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

if N == K:
    print(1)
elif A[0] == 1 or A[N-1] == 1:
    print(math.ceil((N-K) / (K-1)+1))
else:
    if N % 2 == 1 and K % 2 == 1 and A.index(1) == ((N // 2)+1):
        print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-1))-1)
    else:
        print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-1)))

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = [int(_) for _ in input().split()]
min_index = a.index(1)
left = min_index
right = min_index
cnt = 0
while left > 0 or right < n - 1:
  if left > 0:
    left -= (k - 1)
    cnt += 1
  if right < n - 1:
    right += (k - 1)
    cnt += 1

if k - 2 > min_index or min_index > n - k - 2:
  cnt -= 1
print(cnt if n > k else '1')

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
minIndex = A.index(min(A))
if K == len(A):
    print(1)
elif K == 2:
    print(len(A)-1)
else:
    cnt1 = math.ceil((minIndex+1)/K)
    cnt2 = math.ceil((len(A)-minIndex)/(K-1))
    if minIndex == 0:
        cnt1 = 0
    elif minIndex == len(A)-1:
        cnt2 = 0
    print(cnt1 + cnt2)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

inputN, inputK = map(int, input().split())
inputA = list(map(int, input().split()))
minNumber = inputN
minPos = 0

if inputN == inputK:
    print (1)
elif inputN <= (inputK-1)*2 + 1:
    print (2)
elif inputN <= (inputK-1)*3 + 1:
    print (3)
elif inputN <= (inputK-1)*4 + 1:
    print (4)
elif inputN <= (inputK-1)*5 + 1:
    print (5)
else:
    for i in range(len(inputA)):
        if inputA[i] < minNumber:
            minNumber = inputA[i]
            minPos = i

    splitNumber = (inputN + 1) / (inputK - 1)
    print (int(splitNumber))

Submission status: Wrong Answer

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


def retminvalue(syou):
    mini = 0
    mini += syou // (K-1)
    if(syou % (K-1) != 0):
        mini += 1
    return mini

for i in range(N):
    if A[i] == 1:
        p = i+1

if p == 0 or p==(N):
    print(retminvalue(N))
else:
    minlist = [99999 for i in range(K+3)]
    for i in range(K-1):
        minlist[i] =  retminvalue(N-p+i) + retminvalue(p-1+i)
    print(min(minlist))

Submission status: Wrong Answer

Solution code:
from math import floor
nk = input()
n, k = nk.split()
n = int(n)
k = int(k)

an = input()
an_list = an.split()
min = min(an_list)

min_ind = an_list.index(min) + 1
after = (n - min_ind) / (k-1)
before = (min_ind - 1) / (k-1)

res = 0

if min_ind < k or (n - min_ind) > (k-1):
    res = floor(n/(k-1))

elif n < k:
    res = 1

else:
    if after.is_integer():
        res = res + after
    else:
        res = res + floor(after) + 1

    if before.is_integer():
        res = res + before
    else:
        res = res + floor(before) + 1


print(int(res))

Submission status: Wrong Answer

Solution code:
import sys
N,K = map(int, input().split())
lis = [int(i) for i in input().split()]
if N == 1:
  print(1)
  sys.exit()
ind = lis.index(1)+1
pre = ind-1-1
pos = N-ind-1
if pre%(K-1)==0:
  a = pre//(K-1)
else:
  a = pre//(K-1)+1
if pos%(K-1)==0:
  b = pos//(K-1)
else:
  b = pos//(K-1)+1
print(1+a+b)

Submission status: Wrong Answer

Solution code:
import math

N,K = map(int,input().split())
A = [int(i) for i in input().split()]
 
if N == K:
    print(1)
else:
    print(int(math.ceil(N/(K-1))))

Submission status: Wrong Answer

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

a = list(map(int, input().split()))
plus = 0
minus = 0

for i in range(len(a)):
  if a[i] == 1:
    min = i + 1

if (min-1)%(K-1) + (N-min)%(K-1) >= (K-1):
  minus += 1
  
if (min-1)%(K-1) > 0:
  plus += 1
if (N-min)%(K-1) > 0:
  plus += 1
  
print((min-1)//(K-1) + (N-min)//(K-1) + plus - minus)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
min_idx = A.index(min(A))
tmp = min_idx
count = 0
if K <= min_idx + 1 and K <= N - min_idx - 1:
    while tmp > 0:
        tmp -= (K - 1)
        count += 1
        
    a = N - min_idx - 1
    while a > 0:
        a -= (K - 1)
        count += 1
        
elif K > min_idx + 1 and K <= N - min_idx - 1:
    count = 1
    a = N - min_idx - 2
    while a > 0:
        a -= (K - 1)
        count += 1

elif K <= min_idx + 1 and K > N - min_idx - 1:
    while tmp > 0:
        tmp -= (K - 1)
        count += 1
    count += 1
elif N == K:
    count = 1
    
else:
    count = 2
    
    
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def get_score(amount, limit):
    if amount == 0:
        return 0
    s = limit - 1
    tmp = amount // s
    return tmp if (amount % s) == 0 else tmp + 1


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

key = a.index(1)
left = key
lt = k - left - 1
right = n - key - 1
rt = k - right - 1

r_tmp = lt if lt > 0 else 0
r1 = get_score(left, k)
if r1 != 0:
    r1 = r1 + get_score(right - r_tmp, k)
else:
    r1 = r1 + get_score(right, k)

l_tmp = rt if rt > 0 else 0
r2 = get_score(right, k)
if r2 != 0:
    r2 = r2 + get_score(left - l_tmp, k)
else:
    r2 = r2 + get_score(left, k)

print(min(r1, r2))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a_tmp = input().split()
a = [[] for i in range(n)]
for i in range(n):
    a[i] = int(a_tmp[i])
a1 = a.index(1)
sol = 0
if k <= n//2:
    a_left = a1
    a_right = len(a)-1-a1
    if a_left % (k-1) == 0:
        sol += int(a_left / (k-1))
    else:
        sol += int(a_left / (k-1)) + 1
    if a_right % (k-1) == 0:
        sol += int(a_right / (k-1))
    else:
        sol += int(a_right / (k-1)) + 1
    print(sol)
elif n > k > n//2:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

S, K = map(int,input().split())

l = list(map(int,input().split()))

one_index=0
min=1 

if(len(l)%(K-1)==0):
    print(int(len(l)/(K-1)))
else:
    print(int(len(l)/(K-1))+1)

Submission status: Wrong Answer

Solution code:
import math
N,K = [int(i) for i in input().split()]
a = list(input().split())
m = a.index('1')
if m == 0 or m == N-1:
    print(math.ceil((N-1)/(K-1)))
else:
    res = (K - N%(K-1))%K
    print(math.ceil((m)/(K-1)) + math.ceil((N-m-1-res)/(K-1)))

Submission status: Wrong Answer

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

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


for i in range(N):
    if A[i]==1:
        min_a=i+1
        break

x = min_a-1
y = N-min_a


ansa=x//(K-1)+y//(K-1)

if x%(K-1)>0:
    ansa=ansa+1
if y%(K-1)>0:
    ansa=ansa+1

#kk = (K-1)//2
#
#if x==y and K%2==1:
#    if (x-kk)%(K-1)==0 and (y-kk)%(K-1)==0:
#       ans = ans-1

kk1 = (K-1)//2
kk0 = K-kk1

if x>y:
    x=x-kk0
    y=y-kk1
else:
    x=x-kk1
    y=y-kk0

ansb = 1+x//(K-1)+y//(K-1)

if x%(K-1)>0:
    ansb=ansb+1
if y%(K-1)>0:
    ansb=ansb+1

if ansa>ansb:
    ans=ansb
else:
    ans=ansa

if N==K:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

inputN, inputK = map(int, input().split())
inputA = list(map(int, input().split()))
minNumber = inputN
minPos = 0

if inputN == inputK:
    print (1)
elif inputN <= (inputK-1)*2 + 1:
    print (2)
elif inputN <= (inputK-1)*3 + 1:
    print (3)
else:
    for i in range(len(inputA)):
        if inputA[i] < minNumber:
            minNumber = inputA[i]
            minPos = i

    splitNumber = (inputN + 1) / (inputK - 1)
    print (int(splitNumber))

Submission status: Wrong Answer

Solution code:
n,k = input().split(' ')
n,k = int(n),int(k)
p = list(input())
ans = 0
a,b = len(p[: k-1]),len(p[k:])

if n <= k:
    ans = 1
if min(p[: k-1]) < min(p[k:]):
    while n > 0:
        n = n - k + 1
        ans += 1
else:
    idx = p.index(min(p[k:]))
    if idx + 1 < len(p) - k:        
        while n > 0:
        	n = n - k + 1
        	ans += 1
    else:
        if a < b:
            a = a - n + 1
            while a > 0:
                a = a - n + 1
                ans += 1
            while b > 0:
                b = b - n + 1
                ans += 1
        else:
            b = b - n + 1
            while a > 0:
                a = a - n + 1
                ans += 1
            while b > 0:
                b = b - n + 1
                ans += 1
      
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    argmin = 0
    for i in range(N):
        if 1 == int(input_raw[i]):
            argmin = i
    if K == N:
        print 1
        exit()
##    if argmin  < K - 1:
##        argmin = K - 1
##    if argmin  > N - K and argmin + 1 < N:
##        argmin = N - K
    min_op = sys.maxint
    for i in range(K):
        L = argmin - i
        R = ((N - 1) - argmin ) - (K - 1) + i
        if L < 0:
            L = 0
        if L > N:
            L = N
        if R > N:
            R = N
        if R < 0:
            R = 0
        op = (L/(K -1) + L % (K -1)) + (R/(K -1) + R % (K -1)) + 1
        if op < min_op:
            min_op = op
    print min_op


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil

n,k=map(int,input().split())
a=list(map(int,input().split()))
i=a.index(1)
print(ceil(i/(k-1))+ceil((n-1-i)/(k-1)))

Submission status: Wrong Answer

Solution code:
import random

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

array = list(range(1, N+1))
random.shuffle(array)
min_index = array.index(min(array))
right_num = len(array) - (min_index+1)
left_num = len(array) - (right_num+1)

cur_index = 1
count = 0
while True:
    if cur_index <= right_num+1:

        count += 1
        cur_index += K-1
    else:
        break

cur_index = 1
while True:
    if cur_index <= left_num+1:
        count += 1
        cur_index += K-1
    else:
        break

print(count-1)

Submission status: Wrong Answer

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

min_position = A.index(1)
left = min_position
right = N - 1 - left
min_num = N

if (left >= K and right >= K):
    for k in range(K):
        left_num = max(0, left + k)
        right_num = min(0, right + K - 1 - k) 
        min_num = min(min_num, (left_num + 1) // (K - 1) + (right_num + 1) // (K - 1) + 1)
    print(min_num)
else:
    print((N - K + 1) // (K - 1) + 1)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
lis=map(int,input().split())
ans=0
for i,x in enumerate(lis):
    if x==1:
        break
n1=N-i-1
n2=i+1

if n1==1:
    pass
elif n1<=K:
    ans+=1
else:
    while n1>0:
        n1-=K-1
        ans+=1

if n2==1:
    pass
elif n2<=K:
    ans+=1
else:
    while n2>0:
        n2-=K-1
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#c
count = 0
N,K = map(int,input().split( ))
J = list(map(int,input().split( )))
for i,j in zip(range(N),J):
    if j==1:
        s = i
        t = i
for _ in range(N):
    if s<=0:
        break
    else:
        s -= K-1
        count += 1

for _ in range(N):
    if t>=N-1:
        break
    else:
        t += K-1
        count += 1
        
if N==K:
    count = 1
print(count)

Submission status: Wrong Answer

Solution code:
import math

def calc_manipulate_times(Klen,len):
    if Klen == 0:
        return 0
    elif Klen<=len:
        return 1
    else:
        return math.ceil((len - Klen)/(Klen-1)) + 1

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

left_count = A.index('1')
right_count = len(A)-A.index('1')-1
# print(A)
# print(left_count)
# print(right_count)
# print(K)
#
# print(int(math.ceil(left_count/K)))
# print(int(math.ceil(right_count/K)))

ans = calc_manipulate_times(left_count,N) + calc_manipulate_times(right_count,N)
print(ans)

Submission status: Wrong Answer

Solution code:
def m():
    def solve(n,k):
        if n <= k:
            return 1
        tmp = 1
        tmp += (n-k) // (k-1)
        if n-k % k-1 == 0:
            return tmp
        return tmp + 1

    def new_solve(n,k,ary):
        if n <= k:
            return 1
        pos = ary.index(1)
        if pos <= k-1 or pos >= n - k:
            return solve(n,k)
        if k % 2 == 0:
            div = k // 2
            left = ary[:pos + (div - 1)]
            right = ary[pos + (div - 1):]
        else:
            div = k // 2
            left = ary[:pos + (div - 1)]
            right = ary[pos + (div):]
        left[len(left)-1] = 1
        right[0] = 1
        return new_solve(len(right),k,right) + new_solve(len(left),k,left)

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    return new_solve(n,k,a)
    # pos = a.index(1)
    # ans = 1
    # if pos <= k-1 or pos >= n - k:
    #     return solve(n,k)
    # if k % 2 == 0:
    #     div = k // 2
    #     left = a[pos+(div-1):]
    #     right = a[:pos+(div-1)]
    # else:
    #     div = k // 2
    #     left = a[pos+(div-1):]
    #     right = a[:pos+(div)]
    # ans += solve(len(left), k) + solve(len(right),k)
    # return ans
print(m())

Submission status: Wrong Answer

Solution code:
import math

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

if N == K:
    print(1)
elif A[0] == 1 or A[N-1] == 1:
    print(math.ceil((N-K) / (K-1)+1))
else:
    if N % 2 == 1 and K % 2 == 1 and A.index(1) == (N // 2):
        print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-1))-1)
    else:
        print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-1)))

Submission status: Wrong Answer

Solution code:
import math

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

inde = A.index(1)

if inde == 0 or inde == N-1:
	print(math.ceil((N - 1) / (K-1)))
elif inde <= K or N - inde - 1 <= K:
	print(1 + math.ceil((N-K)/(K-1)))
else:
	print(math.ceil(inde / (K-1)) + math.ceil((N - inde - 1) / (K-1)))

Submission status: Wrong Answer

Solution code:
import math

s = input().rstrip().split()

n = int(s[0])
k = int(s[1]) - 1

a = input()

block = math.ceil(n / k)

if(n == k + 1):
    print(1)
else:
    print(block)

Submission status: Wrong Answer

Solution code:
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
index1=a.index(1)
ans=float("inf")
for i in range(k):
    ans=min(ans,1+round((index1+1-k+i)/k)+round((n-(index1+1+i))/k))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N, K = [int(i) for i in input().split()]
An = [int(A) for A in input().split()]

index_1 = An.index(min(An))

num_of_leftside = len([i for i in range(0, index_1)])
num_of_rightside = len([i for i in range(index_1+1, N)])

#print(index_1)
#print(num_of_leftside, num_of_rightside)

count = 0
if num_of_leftside % 2 == 1 and num_of_rightside % 2 == 1:
    if K % 2 == 1:
        num_of_leftside -= (K-1)//2
        num_of_rightside -= (K-1)//2
        count += 1
        count +=  int(math.ceil(num_of_leftside / (K-1)))
        count +=  int(math.ceil(num_of_rightside / (K-1)))
    else:
        num_of_leftside -= (K-1)//2 + 1
        num_of_rightside -= (K-1)//2
        count += 1
        count +=  int(math.ceil(num_of_leftside / (K-1)))
        count +=  int(math.ceil(num_of_rightside / (K-1))) 
elif num_of_leftside % 2 == 1 and num_of_rightside % 2 == 0:
    if K % 2 == 1:
        num_of_leftside -= (K-1)//2
        num_of_rightside -= (K-1)//2
        count += 1
        count +=  int(math.ceil(num_of_leftside / (K-1)))
        count +=  int(math.ceil(num_of_rightside / (K-1)))
    else:
        num_of_leftside -= (K-1)//2 
        num_of_rightside -= (K-1)//2 + 1
        count += 1
        count +=  int(math.ceil(num_of_leftside / (K-1)))
        count +=  int(math.ceil(num_of_rightside / (K-1))) 
elif num_of_leftside % 2 == 0 and num_of_rightside % 2 == 1:
    if K % 2 == 1:
        num_of_leftside -= (K-1)//2
        num_of_rightside -= (K-1)//2
        count += 1
        count +=  int(math.ceil(num_of_leftside / (K-1)))
        count +=  int(math.ceil(num_of_rightside / (K-1)))
    else:
        num_of_leftside -= (K-1)//2 + 1
        num_of_rightside -= (K-1)//2
        count += 1
        count +=  int(math.ceil(num_of_leftside / (K-1)))
        count +=  int(math.ceil(num_of_rightside / (K-1)))
else:
    count = int(math.ceil(num_of_leftside / (K-1))) + int(math.ceil(num_of_rightside / (K-1)))  
print(count)

Submission status: Wrong Answer

Solution code:
from math import floor
nk = input()
n, k = nk.split()
n = int(n)
k = int(k)

an = input()
an_list = an.split()
min = min(an_list)

min_ind = an_list.index(min) + 1
after = (n - min_ind) / (k-1)
before = (min_ind - 1) / (k-1)

res = 0

if min_ind < k or (n - min_ind) > (k-1):
    res = floor(n/(k-1))

else:
    if after.is_integer():
        res = res + after
    else:
        res = res + floor(after) + 1

    if before.is_integer():
        res = res + before
    else:
        res = res + floor(before) + 1


print(int(res))

Submission status: Wrong Answer

Solution code:
import sys
N,K = map(int, input().split())
lis = [int(i) for i in input().split()]
if N == 1:
  print(1)
  sys.exit()
ind = lis.index(1)+1
pre = ind-1
pos = N-ind
if pre%(K-1)==0:
  a = pre//(K-1)
else:
  a = pre//(K-1)+1
if pos%(K-1)==0:
  b = pos//(K-1)
else:
  b = pos//(K-1)+1
print(1+a+b)

Submission status: Wrong Answer

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

min_position = A.index(1)
left = min_position
right = N - 1 - left
min_num = N

if (left >= K and right >= K):
    for k in range(K):
        left_num = max(0, left + k)
        right_num = min(0, right + K - 1 - k) 
        min_num = min(min_num, (left_num + 1) // (K - 1) + (right_num + 1) // (K - 1) + 1)
    print(min_num + 1)
else:
    print((N - K + 1) // (K - 1) + 1)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
L= map(int, input().split())
l=list(L)
if N-K<=1:
	if N%K==0:
		print(int(N/K))
	else:
		print(int(N/K+1))
else:
	print(int(N/K+2))

Submission status: Wrong Answer

Solution code:
from sys import stdin



n_s, k_s = stdin.readline().rstrip().split() # 問題文に出てくるA，B，Cが空白区切りで1行で入力される場合はアンパック代入が便利
a_s_l = stdin.readline().rstrip().split() # 問題文に出てくるA，B，Cが空白区切りで1行で入力される場合はアンパック代入が便利

N = int(n_s)
K = int(k_s)
#A = []
"""
for i in a_s_l:
    A.append(int(i))
"""
A = list(map(int, a_s_l))
#AA = A
count = 0
j = K - 1
for i, a in enumerate(A):
    if N == K :
        count = count + 1
        break
    elif i > N - K:
        #buf = A[N - K : N]
        count = count + 1
    elif j== i :
        #buf = A[i : i + K]
        count = count + 1
        j = i + K - 1
    
print(count)

Submission status: Wrong Answer

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

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

min_A = min(A)


ind1 = A.index(1)
len1 = N -ind1
len2 = ind1 + 1

r1= 0
if (len1-1)%(K-1) != 0:
    r1 = 1

r2= 0
if (len2-1)%(K-1) != 0:
    r2 = 1
d = 0



ans1 = (len1-1)//(K-1)+r1 + (len2-1)//(K-1)+r2

ans=[]
ans.append(ans1)
for i in range(1, K):
    ans2 = 0
    r3= 0
    if (len1-i)%(K-1) != 0:
        r3 = 1

    r4= 0
    if (len2-i)%(K-1) != 0:
        r4 = 1
    ans2 = (len1-i)//(K-1)+r3 + (len2-((K-1)-i))//(K-1)+r4 + 1
    ans.append(ans2)


print(min(ans))