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 = list(map(int, input().split()))
A = list(map(int, input().split()))

index_of_1 = A.index(1)

if index_of_1 == 0:
    first = 0
else:
    first = math.ceil((index_of_1 + 1) / K)

if index_of_1 == N - 1:
    latter = 0
else:
    latter = math.ceil((N - index_of_1 + 1) / K)

print(first + latter)

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
alt1 = left//(k-1)+right//(k-1)+1
alt2 = (left+k-2)//(k-1)+(right+k-2)//(k-1)
print(min(alt1,alt2))

Submission status: Wrong Answer

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

    else:
        a[i] = min(a[i],a[i+1],a[i+2])
        a[i+1] = min(a[i],a[i+1],a[i+2])
        a[i+2] = min(a[i],a[i+1],a[i+2])
        ans+= 1
print(ans)

Submission status: Wrong Answer

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

min_idx = numbers.index(1)


if len(numbers) > K:
    if min_idx <= K or min_idx >= len(numbers) - K:
        result = (len(numbers) // (K-1))
        print(result)

    else:
        front = numbers[:min_idx+1]
        back = numbers[min_idx:]

        result = -(-len(front) // (K-1) )
        result += -(-len(back) // (K-1) )
        print(result-1)
else:
    print(1)

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 = i
right = N - i - 1


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

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

print(t)

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

Submission status: Wrong Answer

Solution code:
from math import ceil
n, k = map(int, input().split())
a_list = tuple(map(int, input().split()))
i = a_list.index(1)

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

print(res)

Submission status: Wrong Answer

Solution code:
def solve():
    n, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    if n == k:
        return 1
    k = k - 1
    ans = 0
    if k == 1:
        return n - 1
    if n % k == 0:
        ans = int(n / k)
    else:
        ans = int(n / k) + 1
    return ans


if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

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

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

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

one_index=0
min=1

for i in range(len(l)):
    if l[i]==1:
        one_index=i
        
hidari = one_index
migi = len(l)-one_index-K

if migi<0:
    hidari+=migi
    migi=0

if(hidari%(K-1)==0):
    min+=int(hidari/(K-1))
else:
    min+=int(hidari/(K-1))+1
if(migi%(K-1)==0):
    min+=int(migi/(K-1))
else:
    min+=int(hidari/(K-1))+1
    
print(min)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = [int(x) for x in input().strip().split()]
    line = [int(x) for x in input().strip().split()]
    counter = K - 1
    result = 0
    while counter <= N:
        counter += K - 1
        result += 1
    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

index = 0
for i in range(n):
    if a[i] == 1:
        index = i
        break

count_1 = index
count_2 = n - index -1

r = count_1 % (k-1)
if r == 0:
    q_1 = count_1 // (k-1)
else:
    q_1 = count_1 // (k-1) + 1

count_3 = count_2 - r
if count_3 < 0:
    q_2 = 0
elif count_3 % (k-1) == 0:
    q_2 = count_3 // (k-1)
else:
    q_2 =  count_3 // (k-1) +1

ans = q_1 + q_2

print(int(ans))

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)

if b_c < k:
    a_c = a_c - (k - (b_c + 1))
if a_c < k:
    b_c = b_c - (k - (a_c + 1))


min = 0
min += -(-b_c // (k-1))
min += -(-a_c // (k-1))

print(min)

Submission status: Wrong Answer

Solution code:
import math
def my_round(x, d=0):
    p = 10 ** d
    return float(math.floor((x * p) + math.copysign(0.5, x)))/p

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;
    are = buf1[1] - 1;
    kai1 = my_round(ba/are);
    kai2 = my_round((buf1[0] -(ba+1))/are)
    print(int(kai1+kai2));




if __name__ == '__main__':
    main15()

Submission status: Wrong Answer

Solution code:
import math

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

inde = A.index(1)

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

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

leftCount = math.ceil(first / (c - 1))
rightCount = math.ceil((n - first - 1) / (c - 1))

print(leftCount+rightCount)

Submission status: Wrong Answer

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

cnt=0

for i,e in enumerate(l):
    if e!=min(l):
        #print('a')
        try:
            cnt = cnt +1
            for j in range(K):
                l[i+j]=min(l)
        except:
            print(cnt)

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)
    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:
from math import ceil

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

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

l = len(A)

i = A.index(1)

if (N != K):
    res = ceil((l - 1 - i)/(K-1)) + ceil(i/(K-1))
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()))

i = A.index(1)
ans = -(-len(A[:i])//(K-1)) + -(-len(A[i+1:])//(K-1))

print(ans)

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))
print(result)

Submission status: Wrong Answer

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

min_a = min(a)
space_list = []
space_cnt = 0
for j in a:
    if j == min_a:
        space_list.append(space_cnt)
        space_cnt = 0
    else:
        space_cnt += 1
space_list.append(space_cnt)

output = 0
for l in space_list:
    if l == 0:
        pass
    else:
        sho, yo = divmod(l, k-1)
        if yo == 0:
            output += sho
        else:
            output += sho + 1

print(output)

Submission status: Wrong Answer

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

min_idx = numbers.index(1)


if len(numbers) > K:
    if min_idx < K or min_idx > len(numbers) - K:
        result = (len(numbers) // (K-1) )
        print(result)

    else:
        front = numbers[:min_idx+1]
        back = numbers[min_idx:]

        result = -(-len(front) // (K-1) )
        result += -(-len(back) // (K-1) )
        print(result-1)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import math
def my_round(x, d=0):
    p = 10 ** d
    return float(math.floor((x * p) + math.copysign(0.5, x)))/p

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 == 1):
            ba = i;
    are = buf1[1] - 1;
    kai1 = my_round(ba/are);
    kai2 = my_round((buf1[0] -(ba+1))/are)
    print(int(kai1+kai2));




if __name__ == '__main__':
    main15()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n,k = map(int, input().split())
a = [int(i) for i in input().split()]
x=n
for i in range(n):
    if a[i] == 1:
        x=i
        break

y = n - x - 1

p = (x-1)//(k-1) + (y-1)//(k-1) + 2
q = (n-1)//(k-1) + 1
print(min(p,q))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
tmp= input().rstrip().split(' ')
N=int(tmp[0])
K=int(tmp[1])

tmp= input().rstrip().split(' ')
L = tmp.index("1")


out = L//(K-1) + (N-1-L)//(K-1)

if(L%(K-1)>0):
    out+=1
if((N-1-L)%(K-1)>0):
    out+=1
    
if((L%(K-1) + (N-1-L)%(K-1)) >= (K-1)):
    out -=1
    
print(out)

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
    print(math.ceil(nl / (K - 1)) + math.ceil(nr / (K - 1)))

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)
    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:
#coding: utf-8
import math

if __name__ == "__main__":
    n,k = map(int,input().split())
    a = input().split(" ")
    prev = True
    pre,post = (0,0)
    for i in range(n):
        a[i] = int(a[i])
        if a[i] != 1 and prev == True:
            pre += 1
        if a[i] == 1:
            prev = False
        if a[i] != 1 and prev == False:
            post += 1

    result = 0
    result += math.ceil(pre / (k-1))
    result += math.ceil(post / (k-1))

    print(result)

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 + 1) / (K - 1))
if min_index == N - 1:
    right = 0
else:
    right = int((N - min_index) / (K - 1))
ans = left + right

print(ans)

Submission status: Wrong Answer

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

pos = A.index(1) + 1

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

    if (N - pos) % (K - 1) == 0:
        right = (N - pos) // (K - 1)
    else:
        right = ((N - pos) // (K - 1)) + 1

    print(left + right)

Submission status: Wrong Answer

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

if N <= K:
    print(1)
else:
    one = A.index(1)
    left = int(one // (K-1)) + 1 * (one % (K-1))
    right = int((N -one -1) // (K-1)) + 1 * ((N -one -1) % (K-1))
    print(left + right)

Submission status: Wrong Answer

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

#print(N, K)
#print(A)
if N == K:
    print(1)
elif K == 2:
    print(N-1)
else:
    a = N // (K-1)
    if N - a*(K-1) >= 1:
        print(a+1)
    else:
        print(a)

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:
n , k = map(int, input().split())
if k == 2:
    print(n-1)
elif k == n-1:
    print(2)
else:
    print(n//(k-1))

Submission status: Wrong Answer

Solution code:
def min_index(ls):
    from collections import deque
    min_ls = deque()
    min_n = min(ls)
    for i, a in enumerate(ls):
        if min_n == a:
            min_ls.append(i)
    return min_n, set(min_ls)

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

min_a, min_set = min_index(A)

tmp = 0
result = 0

if N==K:
    print(1)
else:
    for i in range(0,N,K-1):

        while i+tmp+1 in min_set:
            tmp += 1
        result += 1
        if i+tmp >= N:
            break

    print(result)

Submission status: Wrong Answer

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

def count(num, k):
    count = 0
    if num <= k:
        count = 1
    elif (num-k) % (k - 1) == 0:
        count = (num - k) // (k - 1) + 1
    else:
        count = (num - k) // (k - 1) + 2
    return count

min_index = a_list.index(1)
pre = 0
if min_index == 0:
    pre = 0
elif min_index+1 <= k:
    pre = 1
    min_index += k-(min_index+1)
else:
    pre = count(min_index+1, k)
suf = 0
if min_index == n - 1:
    suf = 0
elif n-min_index <= k:
    suf = 1
else:
    suf = count(n-min_index, k)

print(int(pre + suf))

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
	if a[i]==1:
		break
p=i
k-=1

#print(ans)
x=0
for j in range(n-1,p,-k):
	x+=1
#print(x)
for j in range(0,p,k):
	x+=1
y=p%k+1+(n-p-1)%k
if y==k+1:
	x-=1
print(math.ceil(n/k))

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
m = min(A)
m_i = A.index(m)
res = math.ceil(m_i/(K - 1)) + math.ceil((N - 1 - m_i)/(K - 1))
if (m_i < K - 1 and N - 1 - m_i > K - 1) or (N - 1 - m_i < K - 1 and m_i > K - 1):
    res -= 1
print(res)

Submission status: Wrong Answer

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

# スペース区切りの整数の入力
n, k = map(int, input().split())
a = map(int, input().split())

# 出力
# print("{} {}".format(a+b+c, s))
# hoge = map(str, a)
# print(','.join(hoge))
if n == k :
    print("1")
else:
    print(math.ceil(n/(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))

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

if len(A) <= K:
    print(1)
else:
    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

    print(rtn)

Submission status: Wrong Answer

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

print(N // (K-1))

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 = index_1
num_of_rightside = (N-1)-index_1

print(int(math.ceil(num_of_leftside / (K-1))) + int(math.ceil(num_of_rightside / (K-1))))

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:
    print(math.ceil((m)/(K-1)) + math.ceil((N-m-1)/(K-1)))

Submission status: Wrong Answer

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

# 1の位置を見つける
A_1 = A.index(1)

if A_1 == 0:
    left = 0
else:
    left_d = A_1
    left = 0
    while left_d > 0:
        left += 1
        left_d -= K - 1

if A_1 == N - 1:
    right = 0
else:
    right_d = N - A_1 - 1
    right = 0
    while right_d > 0:
        right += 1
        right_d -= K - 1

print(left + right)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

ind = nums.index(1)

print(math.ceil((n-1-ind)/ (k-1)) + math.ceil((ind)/(k-1)))

Submission status: Wrong Answer

Solution code:
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(one_index != n):
    bigger = n-one_index
    while True:
        if(bigger <= 0):
            break
        bigger -= k-1
        count += 1

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

print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math

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

minimum = A[0]
place = 0
for i in range(1,N):
    if A[i]<minimum:
        minimum = A[i]
        place = i

left = (place+1) -1
right = N - (place+1) -1

if left < 0:
    left = 0
if right < 0:
    right = 0
            
if place == 0 or place == N-1:
    times = N//(K-1)
else:      
    times = 1 + math.ceil(left/K) + math.ceil(right/K)

if N == K:
    times = 1

print(times)

Submission status: Wrong Answer

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

print(int(N/2))

Submission status: Wrong Answer

Solution code:
def c_minimization(N, K, A):
    import math
    if K == len(A):
        return 1
    elif K >= (len(A) // 2) + 1:
        return 2
    idx_1 = A.index(1)
    left1_num = len(A[:idx_1])
    right1_num = len(A[idx_1+1:])
    ans = math.ceil(left1_num / (K-1)) + math.ceil(right1_num / (K-1))
    return ans

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
 
line = input().split()
N = int(line[0])
K = int(line[1])
line2 = input()

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
index = a.index(1) + 1
ans = index % (k-1) + (len(a)  - index) % (k-1) + 2
if n - k + 1 > ans:print(ans)
else:print(n - k + 1)

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:])
print(math.ceil(left/(k-1))+math.ceil(right/(k-1)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min_idx = numbers.index(1)


if len(numbers) > K:
    front = numbers[:min_idx+1]
    back = numbers[min_idx:]

    result = -(-len(front) // (K-1) )
    result += -(-len(back) // (K-1) )

    print(result-1)
else:
    print(1)

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:
    left_time = (left + 1) // (k - 1)
    right_time = (right + 1) // (k - 1)
    print(left_time + right_time)
else:
    print(n - 1)

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
x = A.index(1)
y = x + 1
c = 0
if y != 1: c += math.ceil((y-1)/(K-1))
if y != N: c += math.ceil((N-y)/(K-1))
print(c)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
x=k-1
y=n%x
if y==0:
    z=n/x
else:
    z=(n-y)/(x)
print(int(z))

Submission status: Wrong Answer

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

index_of_1 = A.index(1)

first = math.ceil((index_of_1 + 1) / K)
latter = math.ceil((N - index_of_1 + 1) / K)
print(first + latter)

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 = 0
min += -(-b_c // (k-1))
min += -(-a_c // (k-1))

print(min)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding=utf-8

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

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

Submission status: Wrong Answer

Solution code:
n,k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

s = A.index(1)
ans = n//(k-1)

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
idx=A.index(1)
cnt=0
if idx:
    if idx+1<=K:
        cnt=1
        A[:K]=[1]*K
    else:
        cnt=(idx-1)//(K-1)+1
        num=cnt*(K-1)+1
        A[:num]=[1]*num
    A=A[::-1]
    idx=A.index(1)
if idx+1<=K:
    cnt+=1
    A[:K]=[1]*K
else:
    cnt+=(idx-1)//(K-1)+1
    num=cnt*(K-1)+1
    A[:num]=[1]*num
print(cnt)

Submission status: Wrong Answer

Solution code:
def solve():
    n, k = map(int, input().split())
    a_list = list(map(int, input().split()))
    if n == k:
        return 1
    k = k - 1
    ans = 0
    if n % k == 0:
        ans = int(n / k)
    else:
        ans = int(n / k) + 1
    return ans

if __name__ == '__main__':
    print(solve())

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

Submission status: Wrong Answer

Solution code:
#/usr/bin/env python3

import math

if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    n = 100000
    index = 0
    for i, j in enumerate(A):
        if j < n:
            index = i
            n = j

    l = max(index, 0)
    r = max(len(A) - index - 1, 0)

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

Submission status: Wrong Answer

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

buff = []
for i in range(K):
    before = min_idx - i
    after = N - (min_idx+1) - (K-1 - i)

    b = int(before / (K-1))
    a = int(after / (K-1))
    if before != 0:
        b += 1
    if after != 0:
        a += 1

    buff.append(a + b + 1)
print(min(buff))

Submission status: Wrong Answer

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

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

min_A = min(A)

ct_min = A.count(min_A)

a = N - (ct_min -1)
print(a//(K-1)-1+1)

Submission status: Wrong Answer

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

l1 = raw_input().split()

print(N/(K-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))
print((minIndex+1)//K+(len(A)-max(minIndex, 1))//K+1)

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
print(math.ceil(count/2))

Submission status: Wrong Answer

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

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

X = A.index(1) #Xは1のindex

if X<K or N-K<=X:
    ans = 1+((N-K)//(K-1))
    if (N-K)%(K-1)>0: ans += 1
    print(ans)
else:
    min_ans = N
    for i in range(K):
        LR = [X-K+i+1,N-X-1-i]
        #print(LR)
        ans = 0
        for a in LR:
            ans += a//(K-1)
            if a%(K-1)>0: ans += 1
        if ans < min_ans: min_ans = ans
    print(min_ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = [int(_) for _ in input().split()]
print((n % k) + (n // k))

Submission status: Wrong Answer

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

pos = A.index(1) + 1

if (pos - 1) % (K - 1) == 0:
    left = (pos - 1) // (K - 1)
else:
    left = ((pos - 1) // (K - 1)) + 1

if (N - pos) % (K - 1) == 0:
    right = (N - pos) // (K - 1)
else:
    right = ((N - pos) // (K - 1)) + 1

print(left + right)

Submission status: Wrong Answer

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

one = A.index(1)

left = int(one // (K-1)) + 1 * (one % (K-1))
right = int((N -one -1) // (K-1)) + 1 * ((N -one -1) % (K-1))

print(left + right)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
x = a.index(1)
while x%(k-1):
    x += 1
r = x//(k-1)
r += (n-x)//(k-1)
print(r)

Submission status: Wrong Answer

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

tmp= input().rstrip().split(' ')
L = tmp.index("1")


out = L//(K-1) + (N-1-L)//(K-1)

if(L%(K-1)>0):
    out+=1
if((N-1-L)%(K-1)>0):
    out+=1
    
if((L%(K-1) + (N-1-L)%(K-1)) >= (K-1)):
    out -=1
    
print(out)

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))
print(result)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
x = a.index(1)
while x%(k-1):
    x += 1
r = x//(k-1)
print(r,x)
r += (n-x)//(k-1)
print(r)

Submission status: Wrong Answer

Solution code:
import math
N,K=map(int, input().split())
a=list(map(int, input().split()))
where=a.index(1)
R=math.ceil((where)/(K-1)) #1の左の要素の個数はwhere
L=math.ceil((N-where-1)/(K-1))#1の右の要素の個数はN-where-1
print(R+L)

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
x = A.index(1)
y = x + 1
c = 0
if y != 1: c += math.ceil(y/(K))
if y != N: c += math.ceil((N-y+1)/(K))
print(c)

Submission status: Wrong Answer

Solution code:
n , k = map(int, input().split())
print(n//(k-1))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
n-=k
if n==0:
    print(1)
    exit()
print(1+(n+k-1)//(k-1))

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:])
print(math.ceil(left/2)+math.ceil(right/2))

Submission status: Wrong Answer

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

for i, aa in enumerate(a):
    if aa == 1:
        min_idx = i
        break
num_operate = 0
left_remain = min_idx
right_remain = n - min_idx - 1
if left_remain%(k-1) > 0:
    num_operate += left_remain//(k-1)+1
else:
    num_operate += left_remain//(k-1)
# print(num_operate)
if right_remain%(k-1) > 0:
    num_operate += right_remain//(k-1)+1
else:
    num_operate += right_remain//(k-1)

print(num_operate)

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
    L = argmin
    R = (N - 1) - argmin
    print (L/(K -1) + L % (K -1)) + (R/(K -1) + R % (K -1))


if __name__ == '__main__':
    main()