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 = [int(i) for i in input().split()]
An = [int(A) for A in input().split()]

index_1 = An.index(min(An))

if N > 2:
    num_of_leftside = index_1
    num_of_rightside = (N-1)-index_1
else:
    num_of_leftside = len([i for i in range(0, index_1)])
    num_of_rightside = len([i for i in range(index_1, N)])

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

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
while tmp >= 1:
    tmp -= 2
    count += 1

a = (N - min_idx) - 1
while a >= 1:
    a -= 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))

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

Submission status: Wrong Answer

Solution code:
import math, sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]


n, k = LI()
a = LI()
l = len(a[:a.index(1)]) + 1
r = len(a[a.index(1):])

if l == 1:
    left = 0
elif l < k:
    left = 1
else:
    left = math.ceil((l - k) / (k - 1)) + 1

if r == 1:
    right = 0
elif r < k:
    right = 1
else:
    right = math.ceil((r - k) / (k - 1)) + 1

print(left + right)

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:
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 ((l - i) < K):
    i = l - K - 1
    ls = ceil(i/(K-1))
elif (i + 1 < K):
    i = K - 1
    rs = ceil((l - 1 - i)/(K-1))

if (N != K):
    res = ls + rs
elif (N == K):
    res = 1


print(res)

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

if len1 == len2 and len2 == K+1:
    d = 1
print((len1-1)//(K-1)+r1 + (len2-1)//(K-1)+r2 - d)

Submission status: Wrong Answer

Solution code:
import math
def main15():
    strbuf1 = input('');
    strbuf2 = input('');
    strbufs1 = strbuf1.split();
    strbufs2 = strbuf2.split();
    buf1 = [];
    buf2 = [];
    ba = 0;
    for i in range(2):
        buf1.append(int(strbufs1[i]));
    for i in range(buf1[0]):
        buf2.append(int(strbufs2[i]));
        if(buf2[i] == 1):
            ba = i;
            break;
    are = buf1[1] - 1;
    kai1 = math.ceil(ba/are);
    kk = ba - are * kai1;
    kai2 = math.ceil((buf1[0] -(ba+1+kk))/are)
    print(int(kai1+kai2));

def main16():
    strbuf = input('');
    num = int(strbuf);
    kazu = 0;
    number = 1;
    while(kazu<num):


        kazu = kazu + 1;

        number = number + 1;


if __name__ == '__main__':
    main15()

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
n, k = map(int,input().split())
a = list(map(int,input().split()))
i = np.argmin(a)
m = math.ceil(i/(k-1))+math.ceil(((n-1)-i)/(k-1))
print(m)

Submission status: Wrong Answer

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

pos = a.index(1)
start = 0
x = 0
if pos < k:
    start = k - 1
    x += 1
else:
    start = pos
    x += pos // (k - 1)
    if (pos % (k - 1)) != 0:
        x += 1

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

Submission status: Wrong Answer

Solution code:
N,K=[int(i) for i in input().split()]
A=[i for i in input().split()]
if N==K:
    print(N//K)
for i in range(50000):
    if K+1+(K-1)*i<=N and N<=K+(K-1)+(K-1)*i:
        print(i+2)
        break

Submission status: Wrong Answer

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

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


if n/2 < k:
    res = 2

print(int(res))

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)
left=ceil((i+1-k)/(k-1))+1 if i+1-k>=0 else 0
right=ceil((n-k-i)/(k-1))+1 if n-k-i>=0 else 0
print(left+right)

Submission status: Wrong Answer

Solution code:
import math

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

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

one_index = a_list.index(1)

kyori_a=len(a_list)-one_index
kyori_b=one_index+1

if kyori_a>k and kyori_b>k:
  print(math.ceil((n+1)/(k-1)))
else:
  print(math.ceil(n/(k-1)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().rstrip().split(' '))
an = list(map(int, input().rstrip().split(' ')))

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

b_c = an.index(1)
a_c = n - (b_c + 1)

min_count = 0

if an[0] != '1' and an[-1] != '1' and b_c < k and a_c < k:
    min_count += 2
# 左側kが大きい
elif an[0] != '1' and b_c < k:
    a_c = a_c - (k - (b_c + 1))
    min_count += 1
    min_count += -(-a_c // (k-1))
# 右側kが大きい
elif an[-1] != '1' and a_c < k:
    b_c = b_c - (k - (a_c + 1))
    min_count += -(-b_c // (k-1))
    min_count += 1
# 通常
else:
    min_count += -(-b_c // (k-1))
    min_count += -(-a_c // (k-1))

print(min_count)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
input()
if n == k:
    print(1)
    exit()
c = 1
i = 0
while c <= n:
    c += k - 1
    i += 1
print(i)

Submission status: Wrong Answer

Solution code:
import math

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

one_index = a.index(1) + 1
if(n == k):
    print(1)
    exit()

# 大きい方
if(one_index != n):
    bigger = n-one_index
    # while True:
    #     if(bigger <= 0):
    #         break
    #     bigger -= k-1
    #     count += 1
    count += math.ceil(bigger/(k-1))

if(one_index != 1):
    # 小さい方
    one_index -= 1
    # while True:
    #     if(one_index <= 0):
    #         break
    #     one_index -= k-1
    #     count += 1
    count += math.ceil(one_index/(k-1))

print(count)

Submission status: Wrong Answer

Solution code:
def endo(N, K):
    result=(N-1)//(K-1)
    if not (N-1)%(K-1)==0:
        result+=1

    return result

N,K=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
i=A.index(1)+1
if i==1 or i==N:
    result=endo(N,K)
else:
    result=max([endo(i,K)+endo(N-i+1,K), endo(i-1,K)+endo(N-i,K)+1])
print(result)

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 = left - k
        right_num = 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())

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


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

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

if N==K:
    ans = 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
st = str(input())
tmp = st.split(" ")
N = int(tmp[0])
K = int(tmp[1])
y = str(input())
if N <= K:
    print(1)
else:
    print(((N - K + 1) // (K - 1) + 1))

Submission status: Wrong Answer

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

answer=0
if N==K:
    print(1)
elif A.index(1)==0 or A.index(1)==N-1:
    if N-K>K:
        if (N-K)%(K-1) == 0:
            answer=int(1+((N-K)/(K-1)))
        else:
            answer=int(((N-K)/(K-1))+2)
    else:
        answer=2
    print(answer)
else:
    left_items=A.index(1)
    right_items=(N-1)-A.index(1)
    if left_items<K or right_items<K:
        if (N-K)%(K-1) == 0:
            answer=int(1+((N-K)/(K-1)))
        else:
            answer=int(((N-K)/(K-1))+2)
        print(answer)

    left=left_items%(K-1)
    right=right_items%(K-1)
    if left+right+1 == K:
        answer=1+(int(left_items/(K-1))+int(right_items/(K-1)))
        print(answer)
    else:
        answer=1+(int(left_items/(K-1))+int(right_items/(K-1)))+1

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
    if(syou % K != 0):
        mini += 1
    return mini

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

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(N-p+i)
    print(min(minlist))

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

    one_right = n - one_left - 1

    if one_left == 0 or one_right == 0:
        print(n//(k-1))

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

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:
  print(1)

else:
  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 = left - k
        right_num = 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))

Submission status: Wrong Answer

Solution code:
str = input()
n, k = str.split(' ')
ni = int(n)
ki = int(k)
str = input()

if ni == ki:
    print(1)
elif ki == 2:
    print(ni-1)
elif ki == (int(ni/2)+1):
    print(2)
else:
    print(int((ni-1)/(ki-1))+1)

Submission status: Wrong Answer

Solution code:
import math, sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]


n, k = LI()
a = LI()
l = len(a[:a.index(1)])
r = len(a[a.index(1):])

if l == 0:
    left = 0
elif l < k:
    left = 1
else:
    left = math.ceil((l - k) / (k - 1)) + 1

if r == 0:
    right = 0
elif r < k:
    right = 1
else:
    right = math.ceil((r - k) / (k - 1)) + 1

print(left + right)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
input()
if n == k:
    print(1)
    exit()
c = 1
i = 1
while c <= n:
    c += k - 1
    i += 1
print(i)

Submission status: Wrong Answer

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

one = -1  # idx of '1'
for i in range(n):
    if a[i]==1: one = i

if one==0: left=0
elif one<=k: left=1
else:left = math.ceil((one+1)/(k-1))
    
if one==n-1: right=0
elif n-one <=k: right=1
else: right = math.ceil((n-one)/(k-1))

print(left+right)

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

Submission status: Wrong Answer

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

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

ind = arr.index(1)

ans = 0

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

	ans += 1


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

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

print ans

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
lis=map(int,input().split())
ans=0
while N>0:
    N-=(K-1)
    ans+=1
    print(N)
print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
z = input()
c = a%b
d = a//b+c
           
print(d)

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 = left - k
        right_num = right + K - 1 - k 
        min_num = min(min_num, (left_num + 1) // (K - 1) + (right_num + 1) // (K - 1) + 1)
    print(min_num - 2)
else:
    print(1 + (N - K + 1) // (K - 1))

Submission status: Wrong Answer

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

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

ind = arr.index(1)

ans = 0

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


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

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

print ans

Submission status: Wrong Answer

Solution code:
def m():
    def solve(n,k):
        if n <= k:
            return 1
        ans = 1
        ans += (n-k) // (k-1)
        if n-k % k-1 == 0:
            return ans
        return ans + 1
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    pos = a.index(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)]
    return solve(len(left), k) + solve(len(right),k)
print(m())

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
input()
if n == k:
    print(1)
    exit()
c = 1
i = 1
while c <= n:
    c += k
    i += 1
print(i)

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 = left - k
        right_num = 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(1 + (N - K + 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 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)) + (N-A.index(1)-1)//(K-1) + 1)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
 
ind = a.index(1)
 
left = ind
right = n-1-ind
import math
if left<k-1 or right<k-1:
	print (n//(k-1))
else:
	if k>=n:
		print (1)
	else:
		print(int(math.ceil(left/(k-1))+math.ceil(right/(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)

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

Submission status: Wrong Answer

Solution code:
import math
import sys
n, c = map(int, input().split())
if(n==c):
    print(1)
    sys.exit()
num = list(map(int, input().split()))
for i in range(len(num)):
    if num[i] == 1:
        first = i
        break
rightCount = math.ceil((n - first - 1) / (c - 1))
b = c - 1 - ((n - first - 1) % (c - 1))
leftCount = math.ceil((first - b) / (c - 1))
print(leftCount + rightCount)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split()]
input()
if n == k:
    print(1)
    exit()
c = 1
i = 1
while c < n:
    c += k
    i += 1
print(i)

Submission status: Wrong Answer

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

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

for i in range(len(a)):
  if a[i] == 1:
    min = i + 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)

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

if front == 1:
    count += 1
if tail == 1:
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import math

l = raw_input().split()
N = int(l[0])
K = int(l[1])

l1 = raw_input().split()

if(not K == 2):
    print(int(math.floor(N/(K-1))))
else:
    print(int(math.floor(N/(K-1)))-1)

Submission status: Wrong Answer

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

pos = a.index(1)
start = 0
x = 0
if pos <= k:
    start = k - 1
    x += 1
else:
    start = pos
    x += pos // (k - 1)
    if (pos % (k - 1)) != 0:
        x += 1

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

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 = left - k
        right_num = right + K - 1 - k 
        min_num = min(min_num, (left_num + 1) // (K - 1) + (right_num + 1) // (K - 1) + 1)
else:
    print(1 + (N - K + 1) // (K - 1))

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)
left = idx // K + 1
right = (N-1 - idx) // K + 1
print(left + right)

Submission status: Wrong Answer

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
A = map(int, sys.stdin.readline().split())

if K == N:
    print(1)
elif K - 1 == 1:
    print(N - 1)
elif (N % 2 == 0 and K == N // 2) or ((K - 1) > N // 2):
    print(N // (K - 1) + 1)
else:
    print(N // (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)
r = ceil((l - 1 - i)/(K-1))
l = ceil(i/(K-1))
if ((l - i) < K):
    i -= 1
    l = ceil(i/(K-1))
elif (i + 1 < K):
    i += 1
    r = ceil((l - 1 - i)/(K-1))

if (N != K):
    res = l + r
elif (N == K):
    res = 1


print(res)

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
print((len1-1)//(K-1)+r1 + (len2-1)//(K-1)+r2)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
import math
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
one_index = nums.index(1)
left = one_index
right = len(nums[one_index+1:])
if left%k == 0 or right%k == 0 or n==k:
    print(math.ceil(left/(k-1))+math.ceil(right/(k-1))-1)
else:
    print(math.ceil(left/(k-1))+math.ceil(right/(k-1)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
str_n, str_k = input().split()
n = int(str_n)
k = int(str_k)
str_a = input().split()
a = [int(str) for str in str_a]

for i, num in enumerate(a):
    if num == 1:
        fir = i

left = fir
right = n - fir - 1

if k == 2:
    print(n - 1)
elif n == k:
    print(1)
else:
    if left < (k - 1) or right < (k - 1):
        print((n+k-3)//(k-1))

    else:
        left_time = (left + 1) // (k - 1)
        right_time = (right + 1) // (k - 1)
        print(left_time + right_time)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N, K = [int(x) for x in stdin.readline().rstrip().split()]
    A = [int(x) for x in stdin.readline().rstrip().split()]
    idx = A.index(1)
    if idx == 0 or idx == (N - 1):
        result = 0
        tmp_idx = 0
        while True:
            tmp_idx += (K - 1)
            result += 1
            if tmp_idx >= (N - 1):
                break
        print(result)
        return
    if idx < K or idx >= ((N - 1) - (K - 1)):
        result = 1
        tmp_idx = K - 1
        while True:
            tmp_idx += (K - 1)
            result += 1
            if tmp_idx >= (N - 1):
                break
        print(result)
        return
    result = 0
    count = N
    while count > 0:
        count -= (K - 1)
        result += 1
    print(result if N > K else 1)


if __name__ == '__main__':
    main()

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 n1 != n2:
    res = math.ceil(n1/(K-1)) + math.ceil(n2/(K-1))
else:
    res = math.ceil((n1-1)/(K-1)) + math.ceil((n2-1)/(K-1)) + 1
    
print(res)

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

Submission status: Wrong Answer

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

min_index = 0
for index, i in enumerate(A):
    if i == 1:
        min_index = index
        break

if min_index == 0:
    left = 0
else:
    left = int((min_index + K - 2) / (K - 1))
if min_index == N - 1:
    right = 0
else:
    right = int((N - min_index + K - 3) / (K - 1))
ans = left + right

print(ans)

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
up = i
cou = 0
while(up<N-1):
    up = up + M-1
    cou = cou + 1
while(bot>0):
    bot = bot - M-1
    cou = cou + 1

bot = i-1
up = i+1
cou2 = 1
while(up<N-1):
    up = up + M-1
    cou = cou2 + 1
while(bot>0):
    bot = bot - M-1
    cou = cou2 + 1

if(cou2<cou):cou = cou2

print(cou)

Submission status: Wrong Answer

Solution code:
import numpy as np
listA=list(map(int,input().split()))
N=listA[0]
K=listA[1]
A=list(map(int,input().split()))
Anp=np.array(A)
Amin=np.argmin(A)
if(((Amin)%(K-1)==0)^((N-Amin-1)%(K-1)==0)):
    print(int((N-1)/(K-1))+1)
elif(((Amin)%(K-1)==0)&((N-Amin-1)%(K-1)==0)):
    if(N/K==1):
        print(1)
    else:
        print((N-1/(K-1)))
else:
     print(int((N-1)/K)+2)

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

print(int(n / (k - 1)))

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+1-k)/(k-1))+1+ceil((n-i-k+1)/(k-1))+1)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = [int(a) for a in input().split()]
A.sort()
j = 0
while(j < (N // K + 1)*(K - 1)):
    for k in A[j:j+3]:
        k = A[j]
    j += K - 1

j = j // (K - 1)

if N % K != 0:
    for k in A[-3:]:
        k = A[-3]
    j += 1

print(j)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
n, k = map(int,input().split())
a = list(map(int,input().split()))
i = np.argmax(a)
m = math.ceil(i/(k-1))+math.ceil(((n-1)-i)/(k-1))
print(m)

Submission status: Wrong Answer

Solution code:
def endo(N, K):
    result=(N-1)//(K-1)
    if not (N-1)%(K-1)==0:
        result+=1

    return result

N,K=map(int,input().split(' '))
A=list(map(int,input().split(' ')))
i=A.index(1)+1
result=max([endo(i,K)+endo(N-i+1,K), endo(i-1,K)+endo(N-i,K)+1])
print(result)

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

for k in range(K):
    left_num = left - k
    right_num = right + K - 1 - k 
    min_num = min(min_num, (left_num + 1) // (K - 1) + (right_num + 1) // (K - 1) + 1)

print(min_num)

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
a = list(map(int, input().split()))
if n % k == k-1 and int(n/k) == 1:
    print(2)
else:
    print(int(math.floor((n/(k-1)))))

Submission status: Wrong Answer

Solution code:


def main():
    import math
    n, k = list(map(int, input().split()))
    #print(n, k)
    row = list(map(int, input().split()))
    #print(row.index(11))
    migigawa = math.ceil(row.index(1) / (k-1))
    #print(row.index(1)+1 , k)
    #print(migigawa)
    if migigawa == 0: n -= 1
    hidarigawa = math.ceil((n - migigawa * k) / (k-1))
    #print(hidarigawa)
    print(migigawa + hidarigawa)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
A = list(map(int, input().split()))
tmp = A.index(1)
x = -(-tmp//(k-1))
if k > tmp+1 and k - 1 < n - 1: tmp += k - (tmp+1)
y = -(-(n-1-tmp)//(k-1))
ans = x+y
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 A[0] == 1 or A[N-1] == 1:
    print(math.ceil((N-K) / (K-1)+1))
else:
    print(((A.index(1)+1)-1)//(K-1) + (N-A.index(1)-1)//(K-1) + 1)

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

if sol != 0:
    print(sol)
else:
    print(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)//2
count += (tail + 1)//2
if front <= 1:
    count += 1
if tail <= 1:
    count += 1

print(count)

Submission status: Wrong Answer

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

if N==K:
    print(1)
else:
    print(N//(K-1) + (1 if N%(K-1) != 0 else 0))