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 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:
        if A.index(1) == ((N // 2)) or 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)))
        else:
            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 = map(int, input().split())
A = list(map(int, input().split()))
m = min(A)
res = 0

min_num = A.index(m)
  
n1 = min_num 
n2 = N - min_num - 1

if K < min(n1, n2):
    res = math.ceil((n1-1)/(K-1)) + math.ceil((n2-1)/(K-1)) + 1
elif min(n1, n2) <= K <= max(n1, n2):
    res = math.ceil((max(n1, n2) - (K - min(n1, n2)-1))/(K-1)) + 1
else:
    res = math.ceil(N/K)

print(res)

Submission status: Wrong Answer

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

while True:
    if i==len(A):
        break
    for i in range(count*K,(count+1)*K):
        if i==len(A):
            break
        elif i==0:
            pass
        else:
            A[i]=A[0]

    count+=1
        
print(count)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a_min = min(a)
a_min_index = a.index(min(a))
left = a_min_index
right = n - a_min_index - 1
import math
result = math.ceil(left / (k - 1)) + math.ceil(right / (k - 1))
if (n % 2 != 0) and (a_min_index + 1) == math.ceil(n/2):
    if k >= math.ceil(n/2):
        print(2)
    elif k == 2:
        print(n-1)
    else:
        print(n-k-(math.ceil(n/2)-3)-(k-3))
elif (a_min_index == 1) or (a_min_index == n):
    print(result + 1)
elif n == k:
    print(1)
else:
    print(result)

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)//(k-1))
else:
    print((n-k)//(k-1) + 1)

Submission status: Wrong Answer

Solution code:
import math


def minimization(N, K, A):
    i = A.index(1)
    n = math.ceil(i / (K - 1))
    if i == len(A) - 1:
        p = 0
    elif N - i <= K:
        p = 1
    else:
        p = math.ceil((N - i - 1) / (K - 1))
    return n, p


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

n_minus, n_plus = minimization(N, K, A)
print(n_minus + n_plus)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = map(int,input().split())
a = list(map(int,input().split()))
start = [i for i,x in enumerate(a) if x == min(a)]
m = 10000000
for i in start:
    if np.ceil(i/(k-1))+np.ceil(((n-1)-i)/(k-1)) < m:
        m = np.ceil(i/(k-1))+np.ceil(((n-1)-i)/(k-1))
print(m)

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-1:])

if n <= k:
    ans = 1
elif min(p[: k-1]) < min(p[k-1:]):
    while n > 0:
        n = n - k + 1
        ans += 1
else:
    idx = p.index(min(p[k-1:]))
    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 math

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

if K == 2:
    print(int(math.ceil(N/(K-1)))-1)

else:
    print(int(math.ceil(N/(K-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

if(N-1-i<=M):
    up = N-1
    bot = i - (M-1-N-1-i)
    cou = 1
if(i<=M):
    bot = 0
    up = i + (M-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:
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
l = N+math.floor(N/K)
print(math.ceil(l/K) if N!=K else 1)

Submission status: Wrong Answer

Solution code:
n,k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
op = a.index(1)
left = op
right = n-op-1
if (left%(k-1))+(right%(k-1))<=k-1:
    print(left//(k-1)+right//(k-1)+1)
else:
    print((left+k-2)//(k-1)+(right+k-2)//(k-1))

Submission status: Wrong Answer

Solution code:
info = list(map(int, input().split(' ')))
array = list(map(int, input().split(' ')))

if info[1] == info[0]:
    print(1)
elif info[1] == 2:
    print(info[0]-1)
elif info[0]//(info[1]-1)==1:
    print(2)
else:
    print(info[0]//(info[1]-1))

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)

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

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
lst = [int(x) for x in input().split()]
k -= 1
one = lst.index(1)
if n == 1:
    print("0")
elif (n-1) < k:
    print("1")
else:
    ans = -(-one // k) - ((-n +one +1) // k)
    if one % k > 0 and (n - 1) % k == 0:
        ans -= 1
    print(str(ans))

Submission status: Wrong Answer

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

# if N == K:
#     print(1)
# elif N - K == 1:
#     print(2)
# else:
#     print(N/K-1)

if N == K:
     print(1)
elif N - K < N/2 :
    print(2)
else:
    print(N-K-1)

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:
        print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-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 = map(int,input().split())
A = [int(i) for i in input().split()]
 
if N == K:
    print(1)

if N % 2 == 1 and K == 2:
    print(int(math.ceil(N/(K-1)))-1)

else:
    print(int(math.ceil(N/(K-1))))

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 and tail >= K) or (tail == N - 2 and front >= K):
    count -= 1

print(count)

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

    idx = min_idx
    while idx > 0:
        idx -= k
        rtn += 1

    if not((N - 1 - min_idx) % K) or not(min_idx%K):
        rtn -= 1

    print(rtn)

Submission status: Wrong Answer

Solution code:
n,k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
op = a.index(1)
left = op
right = n-op-1
if (left%(k-1))+(right%(k-1))==k-1:
    print(left//(k-1)+right//(k-1)+1)
else:
    print((left+k-2)//(k-1)+(right+k-2)//(k-1))

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)*10000 + 1:
    for i in range(2, 10001):
        if inputN <= (inputK-1)*i + 1:
            print (i)
            break
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()))

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) // (K - 1)) + (-(-right_num) // (K - 1)) + 1)
    print(min_num)
else:
    print((-(-N + K) // (K - 1)) + 1)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
A = list(map(int, input().split()))
tmp = A.index(1)
x = -(-(tmp+1)//(k-1))
if k > tmp+1: tmp += k - (tmp+1)
y = -(-(n-1-tmp)//(k-1))
ans1 = x+y

tmp = A.index(1)
y = -(-(n-1-tmp)//(k-1))
if k > n - tmp:
    hoge = k - (n - tmp)
    tmp -= hoge
x = -(-(tmp+1)//(k))
ans2 = x+y

print(min(ans1, ans2))

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 K==1:
    pass
elif n2==K-1:
    ans+=1
    n1-=1
elif n2==K:
    ans+=1
else:
    while n2>0:
        n2-=K-1
        ans+=1

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


print(ans)

Submission status: Wrong Answer

Solution code:
# coding : utf-8
#import math

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

# 全部を最小値1にする必要がある
minNum = 1
minIndex = A.index(minNum)

# 最小値1の左側の個数
leftNum = minIndex
#print(leftNum)

# 最小値1の右側の個数
rightNum = N - leftNum - 1
#print(rightNum)

# 左側の変換について、最初のステップを右側の数を含めても同じ回数になる場合
leftMod = leftNum % (K-1)
if leftMod != 0:
    rightNum -= leftMod
    if rightNum < 0:
        rightNum = 0

# 右側の変換について、最初のステップを左側の数を含めても同じ回数になる場合
rightMod = rightNum % (K-1)
if rightMod != 0:
    leftNum -= rightMod
    if leftNum < 0:
        leftNum = 0

#leftCount = math.ceil( leftNum / (K-1) )
leftCount = -( -leftNum // (K-1) )

#rightCount = math.ceil( rightNum / (K-1) )
rightCount = -( -rightNum // (K-1) )

ans = leftCount + rightCount

print(ans)

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
if (min-1)//(K-1) == 0 and (N-min)//(K-1) == 0:
  plus += 1
  
print((min-1)//(K-1) + (N-min)//(K-1) + plus - minus)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n_s, k_s = stdin.readline().rstrip().split()
a_s_l = stdin.readline().rstrip().split()

N = int(n_s)
K = int(k_s)

A = list(map(int, a_s_l))

count = 0
j = K - 1
for i, a in enumerate(A):
    if N == K :
        count = count + 1
        break
    elif i > N - K:
        count = count + 1
        break
    elif j== i :
        count = count + 1
        j = i + K - 1
    
print(count)

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 = N-1-i
for _ in range(N):
    if s<=0:
        break
    else:
        s -= K-1
        count += 1

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

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)*100 + 1:
    for i in range(2, 101):
        if inputN <= (inputK-1)*i + 1:
            print (i)
            break
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:
import math

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

if N % 2 == 1 and K == 2:
    print(int(math.ceil(N/(K-1))-1))

else:
    print(int(math.ceil(N/(K-1))))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
N,K = map(int,input().split(" "))
A = list(map(int, input().split(" ")))

F=0
for i in A:
    if i==1:
        X=F 
        Y=N-(F+1)
        break;
    F=F+1

qX=X//(K-1)
qY=Y//(K-1)

modX=X%(K-1)
modY=Y%(K-1)

if modX>0:
    AnsX = qX+1
else:
    AnsX=qX

if modY>0:
    AnsY=qY+1
else:
    AnsY=qY
print(AnsX+AnsY)

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(block - 1)
elif(n == k + 1):
    print(1)
else:
    print(block)

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)

if N % 2 and K == 2:
    print(int(math.ceil(N/(K-1))-1))

else:
    print(int(math.ceil(N/(K-1))))

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))

l = one%(k-1)
r = (n-one-1)%(k-1)
left = min(left, math.ceil((one-r)/(k-1)) )
right = min(right, math.ceil((n-one-1-l)/(k-1)) )

print(int(left+right))

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
if (min-1)//(K-1) == 0 and (N-min)//(K-1) == 0:
  plus += 1
  
print((min-1)//(K-1) + (N-min)//(K-1) + plus - minus)

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)*10 + 1:
    for i in range(2, 11):
        if inputN <= (inputK-1)*i + 1:
            print (i)
            break
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:
import math

def calc_manipulate_times(Klen,len):
    if len == 1:
        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')+1
right_count = len(A)-A.index('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)))
# print(calc_manipulate_times(K,left_count) )
# print(calc_manipulate_times(K,right_count))

ans = calc_manipulate_times(K,left_count) + calc_manipulate_times(K,right_count)
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)

if K == 2:
    print(int(math.ceil(N/(K-1))-1))

else:
    print(int(math.ceil(N/(K-1))))

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 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:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a_min = min(a)
a_min_index = a.index(min(a))
left = a_min_index
right = n - a_min_index - 1
import math
result = math.ceil(left / (k - 1)) + math.ceil(right / (k - 1))
if (n % 2 != 0) and (a_min_index + 1) == math.ceil(n/2):
    if k >= math.ceil(n/2):
        print(2)
    elif k == 2:
        print(n-1)
    else:
        print(n-k-(math.ceil(n/2)-3)-(k-3))
elif n == k:
    print(1)
else:
    print(result)

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)
elif(n % k == 1):
    print(block - 1)
else:
    print(block)

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%2 != 0 and k%2 == 0 and (n-k)%(k-1) != 0:
  	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()))

#len(a) == n

#print(n//(k-1))
long_pla =  a.index(min(a)) + 1
if n%(k-1)==0:
    print(n//(k-1))
elif k == 2:
    print(n//(k-1)-1)

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()] 
A = [int(x) for x in input().split()]
# i = A.index(min(A))
# sum = 0
# ii = 0
# while ii + 1 < i:
#     sum += 1
#     ii += K - 1
if N == K:
    print(1)
else:
    print(int((N - 1) / (K - 1)) + 1)

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-2
pos = N-ind-1
if pre <= 0:
  a = 0
elif pre%(K-1)==0:
  a = pre//(K-1)
else:
  a = pre//(K-1)+1
if pos <= 0:
  b = 0
elif pos%(K-1)==0:
  b = pos//(K-1)
else:
  b = pos//(K-1)+1
print(1+a+b)

Submission status: Wrong Answer

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

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

F=0
for i in A:
    if i==1:
        X=F 
        Y=N-(F+1)
        break;
    F=F+1

qX=X//(K-1)
qY=Y//(K-1)

modX=X%(K-1)
modY=Y%(K-1)

print(F,qX,qY,modX,modY)
if modX>0:
    AnsX = qX+1
else:
    AnsX=qX

if modY>0:
    AnsY=qY+1
else:
    AnsY=qY
print(AnsX+AnsY)

Submission status: Wrong Answer

Solution code:
import math

def calc_manipulate_times(Klen,len):
    if len == 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')+1
right_count = len(A)-A.index('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)))
# print(calc_manipulate_times(K,left_count) )
# print(calc_manipulate_times(K,right_count))

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

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-((K-1)-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(i, ans2)


print(min(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)*10 + 1:
    for i in range(2, 11):
        if inputN <= (inputK - 1) * i + 1:
            print (i)
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:
import math

def calc_manipulate_times(Klen,len):
    if len == 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')+1
right_count = len(A)-A.index('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)))
print(calc_manipulate_times(K,left_count) )
print(calc_manipulate_times(K,right_count))

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

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
lst = [int(x) for x in input().split()]
k -= 1
one = lst.index(1)
if (n-1) < k:
    print("1")

else:
    ans = -(-one // k) - ((-n +one +1) // k)
    if one % k > 0 and (n - 1) % k == 0:
        ans -= 1
    print(str(ans))

Submission status: Wrong Answer

Solution code:
# https://qiita.com/skcvim/items/9eed47f5483679fa66b1
# 行数
N, K = map(int, input().split())
A = [input().split()]

# if N == K:
#     print(1)
# elif N - K == 1:
#     print(2)
# else:
#     print(N/K-1)

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

Submission status: Wrong Answer

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

p = a.index(1)

i = p
tmp = n
while True:
    i = i + k
    if i < tmp:
        a.insert(i,1)
        tmp += 1
    else:
        break

j = p
while True:
    j = j - k
    if j >= 0:
        a.insert(j,1)
    else:
        break

a = list(map(str, a))
a = "".join(a)

a = a.split("1")
if "" in a:
    a.remove("")

size = len(a)
print(size)

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:
    if n % 2 == 0:
        print(2)
    else:
        print(n // 2)
else:
    print(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-1-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:
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:
        if A.index(1) == ((N // 2)):
            print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-1)))
        else:
            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=list(map(int,input().split()))
x=0
l=a.index(min(a))
if l+1>=k:
    if l%(k-1)!=0:
        x=x+l//(k-1)+1
    else:
        x=x+l//(k-1)
else:
    if l==0:
        x=x
    else:
        x=x+1
        l=k-1

if (n-l)>=k:
    if (n-l-1)%(k-1)!=0:
        x=x+(n-l-1)//(k-1)+1
    else:
        x=x+(n-l-1)//(k-1)
else:
    if l==n-1:
        x=x
    else:
        x=x+1
print(1 if n==1 else x)

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 - m%K)%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 = [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 > min_index or min_index > n - k - 2:
  cnt -= 1
print(cnt if n > k else '1')

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, input().split())
a = list(map(int, input().split()))##1 - n

lPos = a.index(1)
rPos = a.index(1)

cnt = 0
while  lPos > 0:
    lPos -= (k - 1)
    cnt += 1

while rPos < (len(a) - 1):
    rPos += (k - 1)
    cnt += 1
 
print(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%2 != 0 and (n-k)%(k-1) != 0:
  	print(n//(k-1) + 1)
else:
    print(n//(k-1))

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)
else:

    if inputN > (inputK-1)*10 + 1:
        for i in range(len(inputA)):
            if inputA[i] < minNumber:
                minNumber = inputA[i]
                minPos = i

        splitNumber = (inputN + 1) / (inputK - 1)
        print (int(splitNumber))
    else:
        for i in range(2, 11):
            if inputN <= (inputK-1)*i + 1:
                print (i)

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+N%K))

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:
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:
    if n % 2 == 0:
        print(2)
    else:
        print(n // 2)
else:
    print(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:
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 <= 0:
  a = 0
elif pre%(K-1)==0:
  a = pre//(K-1)
else:
  a = pre//(K-1)+1
if pos <= 0:
  b = 0
if pos%(K-1)==0:
  b = pos//(K-1)
else:
  b = pos//(K-1)+1
print(1+a+b)