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:
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 = (minIndex+1)//(K-1)
    cnt2 = (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:
"""
最小値で置き換えるなら全ての要素が等しくなったら全て最小値
8 3
k-1づつ隣に影響を及ぼせる
1の位置がiだとしたら(i-1)/(k-1)の切り上げと(N-i)/(k-1)の切り上げ
"""
import math

n , k = map(int, input().split())
b = list(map(int,input().split()))
cnt = 1
i = 0
for t in b:
    if t == 1:
        i = cnt
        break
    cnt += 1

result = math.ceil((i-1)/(k-1)) + math.ceil((n-i)/(k-1))
if ((i-1)/(k-1) - math.floor((i-1)/(k-1))) + ((n-i)/(k-1) - math.floor((n-i)/(k-1))) <= 1:
    result -= 1

print(result)

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:
    if K % 2 == 1:
        count = int(math.ceil(num_of_leftside / (K-1))) + 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)))    
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)*2:
    print (2)
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=[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 sys
N, K = map(int,input().split())
A = list(map(int, input().split()))
if N == K:
    print(1)
    sys.exit()
idx = A.index(1)
res = 0
if idx <= K:
    idx = K-1
    res = 1
else:
    while(True):
        res += 1
        idx -= K - 1
        if idx <= 0:
            break
idx = A.index(1)
if idx <= K:
    idx = K-1
while(True):
    if idx >= N-1:
        break
    res += 1
    idx += K-1

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
minIndex = A.index(min(A))
len1 = minIndex+1
len2 = len(A) - minIndex

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

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) / (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 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 R >= N:
            R = N - 1
        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:
info = list(map(int, input().split(' ')))
array = list(map(int, input().split(' ')))
min_index = array.index(min(array))

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

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
i = A.index(1)
left = len(A[:i])
right = len(A[i+1:])

ans1 = ans2 = ans3 = 1000010
if N<=K:
    print(1)
    exit()

if left >= K-1 and right >= K-1:
    ans = -(-left //(K-1)) + -(-right//(K-1))
else:
    if left <= right:
        tmp = K - (i+1)
        ans = 1 + -(-(right - tmp)//(K-1))
    else:
        tmp = K - (N-i)
        ans = 1 + -(-(left - tmp)//(K-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:
        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:
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:
    count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a= list(map(int,input().split()))
idx = 0
for i in range(len(a)):
    if a[i]==1:
        idx=i
        break
before = idx//(k-1) if idx%(k-1)==0 else idx//(k-1)+1
d = max(0,(n-idx-1-idx%(k-1)))
after = d//(k-1) if d%(k-1)==0 else (d//(k-1)+1 if d !=0 else 0)
print(before+after)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
count = 0
k -= 1

left = a.index(1) 
right = len(a) - left - 1

if left % k == 0:
    count += left // k
else:
    count += left // k + 1

if right % k == 0:
    count += right // k
else:
    count += right // k + 1

amari = left % k + right % k

if left % k != 0 and right % k != 0 and amari >= k - 1:
    count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]
ans = (N + (N % K)) // K
if N != K and ((ans % 3 ==0 and N % 3 != 1) or (ans % 3 == 2 and N % 3 != 2) or (ans % 3 == 1 and N % 3 != 0)):
    ans += 1
    
print(ans)

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)

if i==0:left=0
elif i-k<0:left=1
elif i%(k-1)==0:
    left=i//(k-1)
else:
    left=ceil(i/(k-1))
    
if i==n-1:right=0
elif n-k<i:right=1
elif (n-i-1)%(k-1)==0:
    right=(n-i-1)//(k-1)
else:
    right=ceil((n-i-1)/(k-1))
print(left+right)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    NK = input().rstrip().split(' ')
    N = int(NK[0])
    K = int(NK[1])
    line = input().rstrip().split(' ')
    A = list(map(lambda x: int(x), line))
    
    # 1 の位置から左右の端までK個づづ変更すればよい
    # one = A.index(1)
    if N == K:
        print("1")
        exit()
    right = 0
    left = N -1
    count = 0
    while True:
        right += (K-1)
        count += 1
        if right > left:
            print(count)
            break
        left -= (K-1)
        count += 1
        if right > left:
            print(count)
            break

Submission status: Wrong Answer

Solution code:
import math

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

if N <= K:
    print(1)
    exit()

left = math.ceil(N // 2 / K)
right = math.ceil((N - N // 2 + 1) / K)

print(left + right)

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

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

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 R >= N:
            R = N - 1
        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:
input_1 = input()
input_2 = input()

n, k = input_1.split(' ')
an = input_2.split(' ')

n = int(n)
k = int(k)
an = [int(i) for i in an]

min_index = an.index(min(an))
tmp = 0
count = 0
while True:
    count += 1
    tmp = tmp + k - 1
    if tmp >= min_index + 1:
        break
tmp = n
while True:
    count += 1
    tmp = tmp - k - 1
    if tmp <= min_index + 1:
        break
print(count)

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 = [int(x) for x in input().split()]
minIndex = A.index(min(A))
len1 = minIndex+1
len2 = len(A) - minIndex

if K == len(A):
    print(1)
elif K == 2:
    print(len(A)-1)
else:
    if len1 // 2 < K:
        cnt1 = 1
    else:
        cnt1 = (minIndex+1)//(K-1)

    if len2 // 2 < K:
        cnt2 = 1
    else:
        cnt2 = (len(A)-minIndex)//(K-1)
    if minIndex == 0:
        cnt1 = 0
    print(cnt1 + cnt2)

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
l = list(map(int,input().split()))
min_num = min(l)
num = l.count(min_num)
count = len(l)-num
lists = []
for i in range(n):
    if(l[i] != min_num):
        lists.append(i)
a = math.ceil(count/2)
if len(lists) >=2:
    for i in range(len(lists)-1):
        if(lists[i+1]-2>lists[i]):
            a = a+1
print(a)

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 = [input().split()]

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

Submission status: Wrong Answer

Solution code:
import numpy as np

if __name__ == '__main__':
  nk = input().split()
  N, K = int(nk[0]), int(nk[1])
  inputa = input().split()
  A = np.array(inputa, dtype = np.int64)

  agmn = np.argmin(A)

  res = 0
  res += int(np.ceil((len(A)-agmn-1)/(K-1)))
  res += int(np.ceil((agmn)/(K-1)))
  print(res)

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

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

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()))
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
else:
  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 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:
        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:
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 + 1)//(K-1)
count += (tail + 1)//(K-1)

if front == K - 2:
    count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
minIndex = A.index(min(A))
len1 = minIndex+1
len2 = len(A) - minIndex

if K == 2:
    print(len(A)-1)
else:
    if len1 // 2 < K:
        cnt1 = 1
    else:
        cnt1 = (minIndex+1)//(K-1)

    if len2 // 2 < K:
        cnt2 = 1
    else:
        cnt2 = (len(A)-minIndex)//(K-1)
    if minIndex == 0:
        cnt1 = 0
    print(cnt1 + cnt2)

Submission status: Wrong Answer

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

if N == K:
    Ans = 1
elif K == 2:
    Ans = N -1
else:
    if N%(K-1)==0:
        Ans = N//(K-1)
    else:
         Ans = N//(K-1) + 1

print(Ans)

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(' ')]

    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(" "))
A = list(map(int, input().split(" ")))
llen = A.index(1) # num of element (left)
rlen = N-llen-1
# assert N == llen+rlen+1
# tmp = (K-1)*(llen//K)
# remain = 0
# if tmp == 0:
#     remain = llen + rlen
# else:
#     remain = llen-tmp + rlen
# print(tmp)
# print(remain)
if llen % (K-1) == 0:
    print(llen//(K-1) + math.ceil(rlen/(K-1)))
elif rlen % (K-1) == 0:
    print(rlen//(K-1) + math.ceil(llen/(K-1)))
else:
    tmp = math.ceil(llen/(K-1))
    rlen -= (K-1)*tmp - llen
    print(tmp + rlen//(K-1))

Submission status: Wrong Answer

Solution code:
n=list(map(int,input().split()))
m=list(map(int,input().split()))
x=m.index(1)+1
n[1]=n[1]-1
a=(int((x-1)/n[1])+int((n[0]-x)/n[1]))
if (x-1)%n[1]>0:
    a=a+1
if (n[0]-x)%n[1]>0:
    a=a+1
print(int(a))

Submission status: Wrong Answer

Solution code:
import math

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

if N == K:
    print(1)
else:
    nl = A.index(1)
    nr = N - nl - 1
    if (nl <= (K - 2)) or (nr <= (K - 2)):
        print(math.ceil((N - K) / (K - 1)) + 1)
    else:
        print(math.ceil(nl / (K - 1)) + math.ceil(nr / (K - 1)))

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

l = len(A)

i = A.index(1)
rs = ceil((l - 1 - i)/(K-1))
ls = ceil(i/(K-1))


if (N == K):
    res = 1
elif (((l - i) < K) or (i + 1 < K)):
    res = ceil((l - 1)/(K - 1))
else:
    res = ls + rs


print(res)

Submission status: Wrong Answer

Solution code:
import math

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 = int(math.ceil(left_count/K)) + int(math.ceil(right_count/K))
print(ans)

Submission status: Wrong Answer

Solution code:
N, k = map(int, input().split())
num = input().rstrip().split()

t = 0

for i in range(N):
  if num[i] == "1":
    one = i
    break
    
left = one
right = N - one - 1

if left + right + 1 <= k:
  t = 1
  left=0
  right=0
  
elif left <= k - 1:
  left = 0
  right -= (k - 1) - left - 1
  t += 1
  
elif right <= k - 1:
  right = 0
  left -= (k - 1) - right - 1
  t+=1


while(right > 0):
  right -= (k-1)
  t += 1

while(left > 0):
  left -= (k-1)
  t += 1


print(t)

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 = []
for i in a_s_l:
    A.append(int(i))

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:
import math
N,K = [int(i) for i in input().split()]
a = str(input())
m = a.find('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:
import sys
import math


def main():
    """
    2 <= K <= N <= 10^5
    1 <= ai <= N
    1 <= i <= N
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    ans = f(N, K, A)
    print(ans)


def test_examples():
    nka_ans = [
        (4, 3, [2, 3, 1, 4], 2),
        (3, 3, [1, 2, 3], 1),
        (8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
    ]

    for N, K, A, ans in nka_ans:
        assert f(N, K, A) == ans


def test_ans():
    nka_ans = [
        (5, 2, [1, 2, 3, 4, 5], 4),
        (5, 3, [1, 2, 3, 4, 5], 2),
        (5, 2, [5, 4, 3, 2, 1], 4),
        (5, 3, [5, 4, 3, 2, 1], 2),
    ]

    for N, K, A, ans in nka_ans:
        assert f(N, K, A) == ans


def f(N, K, A):
    """
    数列のうち，連続した K個の要素を選ぶ
    その後，選んだ要素それぞれの値を，選んだ要素の中の最小値で置き換える．
    上の操作を何回か繰り返すことで，この数列の要素をすべて等しくしたい
    必要な操作の回数の最小値


    全体の最小値=1のindexを見つける, 1-idx
        1でない最小値で統一したとき
        最終的に統一できない
            N=3,K=2, 231
            23 to 22: 221

    1-idxを含むKを左右に置き換えていく
        N=3,K=2, 213
        21 to 11: 113
        13 to 11: 111

    Kの範囲がはみだすときは調整
        N=5,K=3, 51234
        513 to 111
    """
    idx = 0
    for i, a in enumerate(A):
        if a == 1:
            idx = i
            break

    ans = 0
    if idx - K + 1 < 0:
        print("A", file=sys.stderr)
        # 左の範囲調整
        idx = K - 1
        ans += 1
        if idx <= N - 2:
            # 残り右
            rest = N - (idx + 1)
            print(idx, rest, file=sys.stderr)
            ans += math.ceil(rest / (K - 1))
    elif idx + K - 1 >= N:
        print("B", file=sys.stderr)
        # 右の範囲調整
        idx = N - K
        ans += 1
        if idx >= 1:
            # 残り左
            rest = idx
            print(idx, rest, file=sys.stderr)
            ans += math.ceil(rest / (K - 1))
    else:
        print("C", file=sys.stderr)
        # 右
        rest = N - (idx + 1)
        ans += math.ceil(rest / (K - 1))
        # 左
        rest = idx
        ans += math.ceil(rest / (K - 1))

    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]
ans = (N + (N % K)) // K
if (ans % 3 ==0 and N % 3 != 1) or (ans % 3 == 2 and N % 3 != 2) or (ans % 3 == 1 and N % 3 != 0):
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = [int(_) for _ in input().split()]
min_index = a.index(min(a))
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 - 1 < min_index < n - k - 1:
  cnt -= 1
print(cnt if n > k else '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 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)
        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())
num = input().rstrip().split()

t = 0

for i in range(N):
  if num[i] == "1":
    one = i
    break
    
left = one
right = N - one - 1

if left + right + 1 <= k:
  t = 1
  left=0
  right=0
  
elif left < k - 1:
  left = 0
  right -= (k - 1) - left - 1
  t += 1
  
elif right < k - 1:
  right = 0
  left -= (k - 1) - right - 1
  t+=1


while(right > 0):
  right -= (k-1)
  t += 1

while(left > 0):
  left -= (k-1)
  t += 1


print(t)

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) // (K - 1) + 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:
    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()))

if n == k:
    count = 1
else:
    if n - k < k:
        count = 2
    else:
        k -= 1
        count = n // k

        if n % k != 0:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
count = 0
k -= 1

left = a.index(1) 
right = len(a) - left - 1

if left % k == 0:
    count += left // k
else:
    count += left // k + 1

if right % k == 0:
    count += right // k
else:
    count += right // k + 1

amari = left % k + right % k

if amari >= k:
    count -= 1

print(count)

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:
    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())
lis=map(int,input().split())
ans=0
for i,x in enumerate(lis):
    if x==1:
        break
n1=N-i-1
n2=i+1
state=0
while n1>0:
    if n1==K and state==0:
        ans+=1
        break
    n1-=K-1
    ans+=1
    state=1

state=0
while n2>0:
    if n2==K and state==0:
        ans+=1
        break
    n2-=K-1
    ans+=1
    state=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
mnidx = A.index(min(A))
left = mnidx-0
right = N-mnidx-1
ans = math.ceil(left/(K-1))
ans += math.ceil(right/(K-1))
print(ans if N!=K else 1)

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
lena = len(a)
index = a.index(1) + 1
lenb = lena - index
if lena / 2 > index:
    front = math.ceil((index-1) / (k-1))
    if k == n :opt = 0
    elif k - index >  0 :opt = k - index
    else :opt = 0
    back = math.ceil((lenb - opt) / (k-1))

else:
    back = math.ceil((lenb-1) / (k-1))
    if k - lenb >  0 :opt = k - lenb
    else :opt = 0
    front = math.ceil((index - opt) % (k-1))

ans = front + back
print(ans)

Submission status: Wrong Answer

Solution code:
N, k = map(int, input().split())
num = input().rstrip().split()

t = 0

for i in range(N):
  if num[i] == "1":
    one = i
    break
    
left = one
right = N - one - 1

if N == k:
  t = 1
  left=0
  right=0
  
elif left < k - 1:
  left = 0
  right -= (k - 1) - left - 1
  t += 1
  
elif right < k - 1:
  right = 0
  left -= (k - 1) - right - 1
  t+=1


while(right > 0):
  right -= (k-1)
  t += 1

while(left > 0):
  left -= (k-1)
  t += 1


print(t)