Problem:


Score : 300 points

Problem Statement

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

2 \leq K \leq N \leq 100000

A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.

In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4



Sample input:
4 3
2 3 1 4


Sample output:
2

Submission status: Wrong Answer

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

one_idx = None
for i in range(N):
    if A[i] == 1:
        one_idx = i
        break

left = one_idx
right = N - one_idx -1

print(math.ceil(left/(K-1)) + math.ceil(right/(K-1)))

Submission status: Wrong Answer

Solution code:
I = raw_input().split(" ")
N = int(I[0])
K = int(I[1])
A = raw_input().split(" ")
X = N / K
Y = N % K
ans = X + Y
print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

a = list(map(int, input("").split()))

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

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

a = list(map(int, input("").split()))

#print(n)
#print(k)
#print(a)

#print(min(a))

print((n//k) + (n%k))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
input() # not important
cnt = 0
while N > 0:
    N -= K-1
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split())
a = list(map(int,input().split()))
print(N,K)
print(math.ceil((N-1)/(K-1)))

Submission status: Wrong Answer

Solution code:
n,k = map(int, raw_input().split())
a = map(int, raw_input().split())
p = a.index(1)
if p+1 < k or n-p < k:
    print (n-1) / (k-1)
else:
    print (p+1) / (k-1) + (n-p) / (k-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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


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


min = li.index(1)

ans = 0
ans1 = 0
ans2 = 0


if min <= K:
	N -= K #1
	ans = math.ceil(N / (K-1)) + 1
	print (ans)
else:
	min = min + 1 - K #ans1 = 1
	ans1 = math.ceil(min / (K-1)) + 1
	N = N - min - K
	ans2 = math.ceil(N / (K-1)) + 1
	print (ans1 + ans2)

Submission status: Wrong Answer

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

idx = A.index(1)

if idx != 0 and idx != N-1:
    a = len(A[:idx-1])
    b = len(A[idx+1:])
    print(-(-a//(K-1))-(-b//(K-1)))
else:
    c = len(A)-1
    print(-(-c//(K-1)))

Submission status: Wrong Answer

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

idx = A.index(1)

if idx != 0 and idx != N-1:
    a = len(A[:idx-1])
    b = len(A[idx+1:])
    print(-(-a//(K-1))-(-b//(K-1)))
elif idx ==0 or idx == N-1:
    c = len(A)-1
    print(-(-c//K))

Submission status: Wrong Answer

Solution code:
import atexit,io,sys,os,math
from collections import OrderedDict
buffer=io.BytesIO()
sys.stdout=buffer
@atexit.register
def write():
    sys.__stdout__.write(buffer.getvalue())

def min(A,n):
    m=A[0]
    x=0
    for i in xrange(n):
        if(A[i]<m): m,x=A[i],i
    return x     
n,k=map(int,raw_input().split())
A=map(int,raw_input().split())
x=min(A,n)
p=0
x1=x
while x1>0: x1,p=x1-(k-1),p+1
x1=x
while x1<n: x1,p=x1+(k-1),p+1
print("%d"%p)

Submission status: Wrong Answer

Solution code:
import atexit,io,sys,os,math
from collections import OrderedDict
buffer=io.BytesIO()
sys.stdout=buffer
@atexit.register
def write():
    sys.__stdout__.write(buffer.getvalue())

def min(A,n):
    m=A[0]
    x=0
    for i in xrange(n):
        if(A[i]<m): m,x=A[i],i
    return x     
n,k=map(int,raw_input().split())
A=map(int,raw_input().split())
x=min(A,n)
a=(x+1)/k
#print(a,(x+1)-k*a)
b=(n-(x+1))/k
#print(b,n-(x+1)-b*k)
p=a+(1 if 0<(x+1)-k*a<k-1 else 2 if k-2<(x+1)-k*a<k else 0) + b +(1 if 0<(n-x-1)-b*k<k-1 else 2 if k-2<(n-x-1)-b*k<k else 0)
print("%d"%p)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

l = n%(k-1)

if l==k-2 or l<=1:
    print(math.floor(n/(k-1)))
else:
    print(math.ceil(n/(k-1)))

Submission status: Wrong Answer

Solution code:
import math

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

if n == k:
    print(1)
else:
    print(math.ceil(n/(k-1)))

Submission status: Wrong Answer

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

import math
import sys

a,b = input().split(" ")

ans = math.floor(int(a) / (int(b)-1))
if int(a) % (int(b)-1) <= 1:
    print(ans)
else:
    print(ans+1)

Submission status: Wrong Answer

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

import math
import sys

a,b = input().split(" ")

ans = math.floor(int(a) / (int(b)-1))
if int(a) & (int(b)-1) <= 1:
    print(ans)
else:
    print(ans+1)

Submission status: Wrong Answer

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

import math
import sys

a,b = input().split(" ")

ans = int(a) / (int(b)-1)

print(math.ceil(ans))

Submission status: Wrong Answer

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

import math
import sys

a,b = input().split(" ")

ans = int(a) / int(b)

print(math.ceil(ans))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
An = list(map(int, input().split()))
p = An.index(1) + 1
ans = 0
if p >= k:
    ans += 1
else:
    if p % k != 0:
        ans += p // k + 1
    else:
        ans += p // k
if len(An) - k <= 0:
    print(ans)
    exit()
if (len(An)-p) % (k-1) != 0:
    ans += (len(An)-p)//(k-1) + 1
else:
    ans += (len(An)-p)//(k-1)
print(ans)

Submission status: Wrong Answer

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

res = n//(k-1)
print(res)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
arr = list(map(int, input().split()))
m = min(arr)

c = 0
ans = 0
for i in arr:
  if i == m:
    c += (ans + K - 2) // (K - 1)
    ans = 0
  else:
    ans += 1
c += (ans + K - 2) // (K - 1)
print(c)

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:
        min_a=i+1
        break

x = min_a-1
y = N-min_a


ans=math.ceil(x/(K-1))+math.ceil(y/(K-1))

if x>y:
    x=x-math.ceil((K-1)/2)
    y=y-math.floor((K-1)/2)
else:
    y=y-math.ceil((K-1)/2)
    x=x-math.floor((K-1)/2)


ans1=1+math.ceil(x/(K-1))+math.ceil(y/(K-1))

if ans>ans1:
    print(ans1)
else:
    print(ans)

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:
        min_a=i+1
        break

x = min_a-1
y = N-min_a


ans=math.ceil(x/(K-1))+math.ceil(y/(K-1))

if x>y:
    x=x-math.ceil(K/2)
    y=y-math.floor(K/2)
else:
    y=y-math.ceil(K/2)
    x=x-math.floor(K/2)
    
ans1=1+math.ceil(x/(K-1))+math.ceil(y/(K-1))

if ans>ans1:
    print(ans1)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

one_idx = lis.index(1)
left = int((one_idx+1)/k if (one_idx+1)%k==0 else (one_idx+1)/k+1)
right = int((n-one_idx+1)/k if (n-one_idx+1)%k==0 else (n-one_idx+1)/k+1)
print(left+right)

Submission status: Wrong Answer

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

# if N == K:
#     print(1)
# elif N - K == 1:
#     print(2)
# else:
#     print(N/K-1)
i = 1
while N-K > 0:
    N = N-K +1
    i = i+1
    print('Nの中身'+str(N))
    print('iの中身'+str(i))

print(i)


    # if N != K:
    #     N = N-K-1
    #     i = i+1
    # else:
    #     N = N-K
    #     i = i-1

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

# 8 2
# 5
#
# 8 3
# 4
#
# 8 4
# 3
#
# 8 5
# 2
#
# 8 6
# 2
# 8 7

# 7 2
# 4
#
# 7 3
#

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

front = 0
tail = 0
count = 0

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

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

if (front == K - 2 and tail >= K and K != 2) or (tail == N - 2 and front >= K and K != 2):
    count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
#abc101c
import math

n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
p=a.index(1)
res=int(math.ceil(1.0*p/(k-1))+math.ceil(1.0*(n-p)/(k-1)))
if a[0]==1 or a[n-1]==1:
 res-=1
print res

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
lista = list(map(int, input().split(" ")))
num = 0
listlist = []
listlist.append(lista)
r = len(lista) - K + 1
m = min(lista)
while(True):
    num += 1
    newlistlist = []
    for tmplist in listlist:
        for i in range(r):
            tmptmplist = tmplist.copy()
            if min(tmptmplist[i:i+K]) == m and max(tmptmplist[i:i+K]) != m:
                for j in range(K):
                    tmptmplist[i + j] = m
                newlistlist.append(tmptmplist)
                # print(tmptmplist)
    mm = min([sum(listb) for listb in newlistlist])
    if mm == m * N:
        break
    listlist = newlistlist
    print(num, len(newlistlist))
print(num)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
lista = list(map(int, input().split(" ")))
num = 0
listlist = []
listlist.append(lista)
r = len(lista) - K + 1
m = min(lista)
while(True):
    num += 1
    newlistlist = []
    for tmplist in listlist:
        for i in range(r):
            tmptmplist = tmplist.copy()
            if min(tmptmplist[i:i+K]) == m and max(tmptmplist[i:i+K]) != m:
                for j in range(K):
                    tmptmplist[i + j] = m
                if len(newlistlist) == 0:
                    newlistlist.append(tmptmplist)
                else:
                    for complist in newlistlist:
                        if complist == tmptmplist:
                            break
                    else:
                        newlistlist.append(tmptmplist)
                # print(tmptmplist)
    mm = min([sum(listb) for listb in newlistlist])
    if mm == m * N:
        break
    listlist = newlistlist
    print(num, len(newlistlist))
print(num)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
lista = list(map(int, input().split(" ")))
num = 0
listlist = []
listlist.append(lista)
r = len(lista) - K + 1
m = min(lista)
while(True):
    num += 1
    newlistlist = []
    for tmplist in listlist:
        for i in range(r):
            tmptmplist = tmplist.copy()
            for j in range(K):
                tmptmplist[i + j] = m
                newlistlist.append(tmptmplist)
    mm = min([sum(listb) for listb in newlistlist])
    if mm == m * N:
        break
    listlist = newlistlist
print(num)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
lista = list(map(int, input().split(" ")))
num = 0
listlist = []
listlist.append(lista)
r = len(lista) - K + 1
m = min(lista)
while(True):
    num += 1
    newlistlist = []
    for tmplist in listlist:
        for i in range(r):
            tmptmplist = tmplist.copy()
            for j in range(K):
                tmptmplist[i + j] = m
            newlistlist.append(tmptmplist)
    mm = min([sum(listb) for listb in newlistlist])
    if mm == m * N:
        break
    listlist = newlistlist
print(num)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
lista = list(map(int, input().split(" ")))
num = 0
listlist = []
listlist.append(lista)
r = len(lista) - K + 1
m = min(lista)
while(True):
    num += 1
    newlistlist = []
    for tmplist in listlist:
        for i in range(r):
            tmptmplist = tmplist.copy()
            for j in range(K):
                tmptmplist[i + j] = m
            newlistlist.append(tmptmplist)
    mm = min([len(set(listb)) for listb in newlistlist])
    if mm == 1:
        break
    listlist = newlistlist
print(num)

Submission status: Wrong Answer

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

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

min_idx = A.index(min(A))

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

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

Submission status: Wrong Answer

Solution code:
from math import ceil
n, k = map(int, input().split())
l = list(map(int, input().split()))
left = l.index(1)
right = n-left+1
if left < (k-1):
  right -= (k-1) - left
ans = ceil(left / k) + ceil(right / k)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
k -= 1
l = list(map(int, input().split()))
left = l.index(1)
right = n-left -1
ans = 0

if left == 0:
  if right % k == 0:
    ans = right // k
  else:
    ans = right // k + 1
elif right == 0:
  if left % k == 0:
    ans = left // k
  else:
    ans = left // k + 1
else:
  if left % k == 0:
    ans += left // k
  else:
    ans += left // k + 1
  
  if right % k == 0:
    ans += right // k
  else:
    ans += right // k + 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(math.floor((n-1+(n%(k-1)))//(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)



if (n-1)%(k-1)==0:
    res = (n-1)/(k-1)
else:
    res = (n-1)//(k-1) + 1

print(res)

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)



if (n-1)%(k-1):
    res = (n-1)/(k-1)
else:
    res = (n-1)//(k-1) + 1

print(res)

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 = floor((n-1)/(k-1))


print(int(res))

Submission status: Wrong Answer

Solution code:
import math
l = 10000000000000000000000000000000
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    if a[i] == 1:
        s = i
        break
for f in range(k-1):
    if 0 <= s + f <= n:
        t = s+f
        m = math.floor((((t+t % (k-1)) // (k-1)) +((n - t-1 + ((n - t-1) % (k-1))) // (k-1))))
        if m < l:
            l = m
print(l)

Submission status: Wrong Answer

Solution code:





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


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


data_list=list(A)

min_index=data_list.index(min(data_list))+1

anser=0

if (min_index-1)%(K-1)==0:
	anser+=(min_index-1)/(K-1)
else : anser+=int((min_index-1)/(K-1))+1

a=(min_index-1)/(K-1)

if (N-min_index)%(K-1)==0:
	anser+=(N-min_index)/(K-1)
else : anser+=int((N-min_index)/(K-1))+1



print(int(anser))

Submission status: Wrong Answer

Solution code:
from math import *
n,k=map(int,input().split())
arr=list(map(int,input().split()))
j=arr.index(min(arr))
ans=0
j=j+1
#print(j)
ans+=ceil((n-j)/(k-1))
ans+=ceil((j-1)/(k-1))
print(ans)

Submission status: Wrong Answer

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

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

min_idx = A.index(min(A))

leftnum = min_idx
rightnum = N - (min_idx + 1)
print((leftnum + rightnum) // (K - 1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if info[1] == info[0]:
    print(1)
elif info[1] == 2:
    print(info[0]-1)
elif info[0]//(info[1]-1)==1:
    print(2)
else:
    print((info[0]-1)//(info[1]-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 min_ind < k or (n - min_ind) > (k-1):
    res = floor(n/(k-1))



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

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


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

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:
        t = i
        break
print(math.floor((((t+t % (k-1)) // (k-1)) + ((n - t-1 + ((n - t-1) % (k-1))) // (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()]
import math
print(math.floor((len(a)-1)/(k-1)))

Submission status: Wrong Answer

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

print((info[0]-1)//(info[1]-1))

Submission status: Wrong Answer

Solution code:
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
print(round((len(a)-1)/(k-1)))

Submission status: Wrong Answer

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

Ans = N-1//(K-1)

print(Ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,raw_input().split())
arr = map(int,raw_input().split())
print (n-1)/(k-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)
if n != k:
    if a1 < k or n-1-k < a1:
        if n-k+1 % k == 0:
            sol = (n-k+1) / k + 1
        else:
            sol = (n-k+1) / k + 2
        print(int(sol))
    else:
        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
        print(sol)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
 
a = list(map(int, input().split()))
plus = 0
minus = 0
 
for i in range(len(a)):
  if a[i] == 1:
    min = i + 1
 
if (min-1)%(K-1) + (N-min)%(K-1) > (K-1):
  minus += 1
  
if (min-1)%(K-1) > 0:
  plus += 1
if (N-min)%(K-1) > 0:
  plus += 1
if (min-1)//(K-1) == 0 and (N-min)//(K-1) == 0:
  plus += 1
 
if N == K:
  print(1)
else:  
  print((min-1)//(K-1) + (N-min)//(K-1) + plus - minus)

Submission status: Wrong Answer

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

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

print(Ans)

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)
print(round((len(a)-k)/(k-1))+1)

Submission status: Wrong Answer

Solution code:
# coding=utf-8


def left_justify(numberlist, n, k):
    ctr = 0
    msr = numberlist.index(1)
    if msr == 0 or msr == n - 1:
        n = n - k
        print(n // (k - 1) + 1)
    else:
        if msr <= k:
            ctr += 1
            right_rest = k - msr
        else:
            left_block = (msr - k) // (k - 1) + 1
            right_rest = (msr - k) % (k - 1)
            ctr += left_block
        right_all = n - msr
        right_all -= right_rest

        if right_all % (k- 1) == 0:
            ctr += right_all // (k - 1)
        else:
            ctr += right_all // (k - 1) + 1
        return ctr


if __name__ == "__main__":
    N, K = map(int, input().split())
    number_list = list(map(int, input().split()))
    ctr = 0

    if N <= K:
        print(1)
    else:
        msr = number_list.index(1)
        if msr == 0 or msr == N-1:
            N = N - K
            print(N//(K-1) + 1)
        else:
            print(min(left_justify(number_list, N, K), left_justify(number_list[::-1], N, K)))

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)
if a1 < k or n-1-k < a1:
    if n-k+1 % k == 0:
        sol = (n-k+1) / k + 1
    else:
        sol = (n-k+1) / k + 2
    print(sol)
else:
    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
    print(sol)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
 
a = list(map(int, input().split()))
plus = 0
minus = 0
 
for i in range(len(a)):
  if a[i] == 1:
    min = i + 1
 
if (min-1)%(K-1) + (N-min)%(K-1) >= (K-1):
  minus += 1
  
if (min-1)%(K-1) > 0:
  plus += 1
if (N-min)%(K-1) > 0:
  plus += 1
if (min-1)//(K-1) == 0 and (N-min)//(K-1) == 0:
  plus += 1
 
if N == K:
  print(1)
else:  
  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(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:
    if minIndex+1 == K:
        cnt1 = 1
    else:
        cnt1 = math.ceil((minIndex)/(K-1))
    if len(A) - minIndex == K:
        cnt2 = 1
    else:
        cnt2 = math.ceil((len(A)-minIndex-1)/(K-1))
    if minIndex == 0:
        cnt1 = 0
    elif minIndex == len(A)-1:
        cnt2 = 0
    print(cnt1 + cnt2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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:
        t = i
        break
print(math.floor(((t+1)//(k-1))+((n-t)/(k-1))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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:
import math
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
minIndex = A.index(min(A))
if K == len(A):
    print(1)
elif K == 2:
    print(len(A)-1)
else:
    if minIndex+1 == K:
        cnt1 = 1
    else:
        cnt1 = (minIndex+1)//(K-1)
    if len(A) - minIndex == K:
        cnt2 = 1
    else:
        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:
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:])

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

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

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = input().split()
line = []
for i in a:
    line.append((int(i)))
print(line)
count = 0
while line.count(1) != 0:
    idx = line.index(1)
    try:
        line.pop(idx - 1)
    except:
        pass
    try:
        line.pop(idx + 1)
    except:
        pass
    finally:
        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:
    if N % 2 == 1 and K % 2 == 1:
        if A.index(1) == ((N // 2)) or A.index(1) == ((N // 2)+1) or  A.index(1) == ((N // 2)-1):
            print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-1)))
        else:
            print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-1))-1)
    else:
        print(math.ceil(((A.index(1)+1)-1) /(K-1)) + math.ceil((N-A.index(1)-1) /(K-1)))

Submission status: Wrong Answer

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

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 = Ans = N//(K-1)
    else:
         Ans = N//(K-1) + 1
            
e = A.index('1') 
if  e < K or N-e <K:
    Ans = Ans + 1
print(Ans)

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



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

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
one_index = nums.index(1)
min = n
for i in range(k):
    left = one_index - i
    right = len(nums[one_index+1:]) - (k - i)
    if left + right > n-1:
        break
    else:
        min_tmp = (-(-left//(k-1)))+(-(-right//(k-1)))
        if min > min_tmp:
            min = min_tmp
print(min)

Submission status: Wrong Answer

Solution code:
import math

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

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

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