Problem:


Score : 300 points

Problem Statement

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

On this sequence, Snuke can perform the following operation:

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

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

Constraints

2 \leq K \leq N \leq 100000

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

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

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

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

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4



Sample input:
4 3
2 3 1 4


Sample output:
2

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
numlist = list(map(int, input().split()))
front = N - (numlist.index(1))
print(front // (K - 1) + (numlist.index(1) + 1) // (K-1))

Submission status: Wrong Answer

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


print(N // (K - 1))

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
numlist = list(map(int, input().split()))
listlengh = len(numlist)
minpos = numlist.index(1) + 1
front = (listlengh - minpos) + 1


print(front // (K - 1 ) + minpos // (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:
n, k = map(int,input().split())
a = list(map(int,input().split()))

t = a.index(1)
ans = 0
if t % (k-1) != 0:
    ans += t // (k-1)
    ans += 1
    t_d = t % (k-1)
else:
    ans += t //(k-1)
    t_d = 0
if t_d != 0:
    d = n - t_d +t + 1
    if d % (k-1) != 0:
        ans += d // (k-1)
        ans += 1
    else:
        ans += d // (k-1)
else:
    d = n - t +1
    if d % (k-1) != 0:
        ans += d //(k-1)
        ans += 1
    else:
        ans += d // (k-1)
print(ans-1)

Submission status: Wrong Answer

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

print(math.ceil(N/(K-1)))

Submission status: Wrong Answer

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

print(math.ceil(N//(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:
n, k = map(int,input().split())
a = list(map(int,input().split()))
ans =  n // (k-1)
print(ans)

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

Submission status: Wrong Answer

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

index = lst1.index(1)

def f_l(now,ct=0):
    while True:
        if now < 0:
            break
        else:
            now -= k-1
            ct += 1
    return ct
def f_r(now,ct=0):
    while True:
        if len(lst1) <= now:
            break
        else:
            now += k-1
            ct += 1
    return ct

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

if index+1 <= k:
    ans = f_r(k-1) + 1
elif n-k <= index:
    ans = f_l(n-k)+1
else:
    del lst1[:(k-1)]
    ans = f_r(0) + 1
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):
        key = i

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

Submission status: Wrong Answer

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

count = 0
for i in range(0, N-K + 1, 2):
	mini = min(perm_N[i:K+i])
	perm_N[i:K+i] = [mini]*K
	count = count + 1
if perm_N[0]*N != sum(perm_N):
	count = count + 1
	print(count)
else:
	print(count)

Submission status: Wrong Answer

Solution code:
## C---------------------------
N , K = map(int, input().split())
perm_N = list(map(int, input().split()))

count = 0
for i in range(0, N-K + 1, 2):
	mini = min(perm_N[i:K+i])
	perm_N[i:K+i] = [mini]*K
	count += 1
if perm_N[0]*N != sum(perm_N):
	count += 1
	print(count)
else:
	print(count)

Submission status: Wrong Answer

Solution code:
nk =list(int(x) for x in input().split())
s = list(int(y) for y in input().split())
def min(a):
  min = 1000000
  for i in range(len(a)):
    if min > a[i]:
      min = a[i]
      index = i
  return index
c = min(s)
num = (c-1)//nk[1] + (len(s)-c)//nk[1] +2
print(num)

Submission status: Wrong Answer

Solution code:
N, K = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
ind_1 = A.index(1)
P, Q = ind_1, N-1-ind_1
print(-(-P//(K-1))-(-Q//(K-1)))

Submission status: Wrong Answer

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

i = A.index(1)
k = K - 1
n = N - 1

ans = (i + k - 1) // k + (n - i + k - 1) // k

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

left = ceil(((N - 1) - A.index(1)) / (K - 1))
right = ceil(A.index(1) / (K - 1))
ans = int(left + right)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

ans = ceil(((N - 1) - A.index(1)) / (K - 1)) + ceil(A.index(1) / (K - 1))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

ans = ceil(((N - 1) - A.index(1)) / 2) + ceil(A.index(1) / 2)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

i = A.index(1)

L = len(A[:i])
R = len(A[i+1:])

ans = ceil(L/(K-1)) + ceil(R/(K-1))

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

i = A.index(1)

L = len(A[:i])
R = len(A[i+1:])

ans1 = ceil(L/(K-1)) + ceil(R/(K-1))

ans2 = 1
if L > 1:
    ans2 += ceil((L-1)/(K-1))
if R > 1:
    ans2 += ceil((R-1)/(K-1))

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
N,K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 2

for x in range(K):
    if a[x] == 1:
        ans += (N - (K-1)) // K
        print(a[x])
        print(ans)
        break
    elif a[N-1-x] == 1:
        ans += (N - (K - 1)) // K
        print(ans)
        break

if ans == 0:
    ans += (N - (K - 1)) // K
    ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 2

for x in range(K):
    print(x)
    if a[x] == 1:
        ans += (N - (K-1)) // K
        print(a[x])
        print(ans)
        break
    elif a[N-1-x] == 1:
        ans += (N - (K - 1)) // K
        print(ans)
        break

if ans == 0:
    ans += (N - (K - 1)) // K
    ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 2

for x in range(K):
    if a[x] == 1:
        ans += (N - (K-1)) // K
        print(ans)
        break
    elif a[N-1-x] == 1:
        ans += (N - (K - 1)) // K
        print(ans)
        break
    else:
        ans += (N - (K - 1)) // K
        ans += 1
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
N,K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 2

for x in range(K):
    if a[x] == 1:
        ans += (N - (K-1)) // K
        print(ans)
        break
    elif a[N-1-x] == 1:
        ans += (N - (K - 1)) // K
        print(ans)
        break
    else:
        ans += (N - (K - 1)) // K
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
N,K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 2

for x in range(K):
    if a[x] == 1:
        ans += (N - (K-1)) // K
        print(ans)
    elif a[N-1-x] == 1:
        ans += (N - (K - 1)) // K
        print(ans)
    else:
        ans += (N - (K - 1)) // K
        print(ans)

Submission status: Wrong Answer

Solution code:
N,K = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 2

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
#1のindexを取得
one_idx = a.index(1)

from decimal import Decimal

left_list_len = one_idx
right_list_len = n - one_idx - 1


print(left_list_len//(k-1)+ right_list_len//(k-1) + min(left_list_len%(k-1),1) + min(right_list_len%(k-1),1))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
#1のindexを取得
one_idx = a.index(1)

from decimal import Decimal

left_list_len = len(a[0:one_idx])
right_list_len = len(a[one_idx::]) - 1


print(left_list_len//(k-1)+ right_list_len//(k-1) + min(left_list_len%(k-1),1) + min(right_list_len%(k-1),1))

Submission status: Wrong Answer

Solution code:
n, k = [int(i) - 1 for i in input().split()]
a = [int(i) for i in input().split()]
o = a.index(1)
l, r = o, n - o
print(-(-l // k) - (-r // k))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()],np.int64)
ans = 0
cnt = 0
minA = np.argmin(A)
leftA = A[:minA]
rightA = A[minA+1:]
x = len(leftA)
y = len(rightA)
for i in [x,y]:
    ans += i // (K-1)
    cnt += i % (K-1)
if cnt % (K-1) == 0:
    ans += cnt % (K-1)
else:
    ans += 1 + cnt % (K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()],np.int64)
ans = 0
minA = np.argmin(A)
leftA = A[:minA]
rightA = A[minA+1:]
x = len(leftA)
y = len(rightA)
for i in [x,y]:
    if i % (K-1) == 0:
        ans += i // (K-1)
    else:
        ans += 1 + i // (K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
i = input()
i = i.split()
N = int(i[0])
K = int(i[1])

i = input()
a = i.split()
L = len(a)
b = []
ans = 0
for i in range(L):
    b.append(int(a[i]))
    if b[i] == 1:
        Min = i

ans = math.ceil(Min / K)
ans = ans + math.ceil((N - Min - 1) / K )
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
flag = 1
ans = 0

while(flag):
  N = N - K + 1
  if N < 0:
    flag = 0
  else:
    ans = ans + 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 1
s  = K

while s < N:
    s = s + (K - 1)
    count = count + 1
    print(s)
print(count)

Submission status: Wrong Answer

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

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


flag = N - 1
count = 0
if N == k:
    flag = -1
    count = 1
while flag >= 0:
    flag -= k-1
    count += 1
    
print(count)

Submission status: Wrong Answer

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

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


flag = N - 1
count = 0
if N == k:
    flag = -1
    count = 1
while flag >= 0:
    flag -= k-1
    count += 1

    
print(count)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
li=[]
import collections
A=collections.Counter(a)
for key in A.keys():
    li.append(key)
x=A[li[0]]    
print(int((n-x)//(k-1)))

Submission status: Wrong Answer

Solution code:
N,K=[int(s) for s in input().split()]
print(N//(K-1)+1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = MAP()

one = A.index(1)
# print(one)

L = one
R = N - L - 1
# print(l, r)
# print(math.ceil(l/(K-1)), math.ceil(r/(K-1)))
# print(L, R)

if K == N:
	print(1)
	sys.exit()

if L == 0:
	l = 0
elif L < K-1:
	l = 1
	R -= K-1-L
else:
	l = math.ceil(L/(K-1))

if R == 0:
	r = 0
elif R < K-1:
	r = 1
	L -= K-1-R
else:
	r = math.ceil(R/(K-1))
# print(l, r)

print(l+r)

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = MAP()

one = A.index(1)
# print(one)

L = one
R = N - L - 1
# print(l, r)
# print(math.ceil(l/(K-1)), math.ceil(r/(K-1)))
# print(L, R)

if K == N:
	print(1)
	sys.exit()

if L == 0:
	l = 0
elif L < K-1:
	l = 1
	R -= 1
else:
	l = math.ceil(L/(K-1))

if R == 0:
	r = 0
elif R < K-1:
	r = 1
	L -= 1
else:
	r = math.ceil(R/(K-1))
# print(l, r)

print(l+r)

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = MAP()

one = A.index(1)
# print(one)

L = one
R = N - L - 1
# print(l, r)
# print(math.ceil(l/(K-1)), math.ceil(r/(K-1)))
# print(L, R)

if K == N:
	print(1)
	sys.exit()

if L < K-1:
	l = 1 if L != 0 else 0
	R -= 1
else:
	l = math.ceil(L/(K-1))

if R < K-1:
	r = 1 if R != 0 else 0
	L -= 1
else:
	r = math.ceil(R/(K-1))

print(l+r)

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = MAP()

one = A.index(1)
# print(one)

L = one
R = N - L - 1
# print(l, r)
# print(math.ceil(l/(K-1)), math.ceil(r/(K-1)))
# print(L, R)

if L < K-1:
	l = 1 if L != 0 else 0
	R -= 1
else:
	l = math.ceil(L/(K-1))

if R < K-1:
	r = 1 if R != 0 else 0
	L -= 1
else:
	r = math.ceil(R/(K-1))

print(l+r)

Submission status: Wrong Answer

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = MAP()

one = A.index(1)
# print(one)

l = one
r = N - l - 1
# print(l, r)

# print(math.ceil(l/(K-1)), math.ceil(r/(K-1)))

print(math.ceil(l/(K-1))+math.ceil(r/(K-1)))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
def count(num):
    if num%(k-1)==0:
        a=(num//(k-1))
    else:
        a=(num//(k-1)+1)
    return a
if n==k:
    print(1)
else:
    one=0
    ans=0
    for i in range(n):
        if a[i]==1:
            one=i+1 #１が左からone番目にある(１スタート)
            break
    l=one-1 #１より左にある数
    r=n-one
    c=0
    if l==0:
        ans+=count(r)
        c=1
    if r==0:
        ans+=count(l)
        c=1
    if l<(k-1) and r<(k-1) and c==0:
        ans+=(count(l)+count(r))
    elif l<(k-1) and (k-1)<=r and c==0:
        r-=((k-1)-l)
        ans+=(count(l)+count(r))
    elif (k-1)<=l and r<(k-1) and c==0:
        l-=((k-1)-r)
        ans+=(count(l)+count(r))
    elif (k-1)<=l and (k-1)<=r and c==0:
        ans+=(count(l)+count(r))
    print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
if n==k:
    print(1)
else:
    one=0
    ans=0
    for i in range(n):
        if a[i]==1:
            one=i+1 #１が左からone番目にある(１スタート)
            break
    l=one-1 #１より左にある数
    r=n-one
    if l!=0:
        if l%(k-1)==0:
            ans+=(l//(k-1))
        else:
            ans+=(l//(k-1)+1)
    if r!=0:
        if r%(k-1)==0:
            ans+=(r//(k-1))
        else:
            ans+=(r//(k-1)+1)
    print(ans)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# 1の位置から幅優先探索の要領で進む。
# 余った両辺の長さの、どちらか一方が割り切れるように調整する
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = k-1
elif n-ini <= k:
    left = n-1 - (k-1)
    right = n-1
else:
    left = ini - (ini%(k-1))
    right = left + (k-1)
# print(left, ini, right)

cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# 1の位置から幅優先探索の要領で進む。
# 余った両辺の長さの、どちらか一方が割り切れるように調整する
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = k-1
elif n-ini <= k:
    left = n-1 - (k-1)
    right = n-1
else:
    left = ini - (ini%(k-1)+1)
    right = left + (k-1)
    for i in range(k-1):
        if left <= n-right+1:
            left-=1
        else:
            right+=1
# print(left, ini, right)
    
cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# 1の位置から幅優先探索の要領で進む。
# 余った両辺の長さの、どちらか一方が割り切れるように調整する
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = k-1
elif n-ini <= k:
    left = n-1 - (k-1)
    right = n-1
else:
    left = ini - (ini%(k-1))
    right = left + (k-1)
    for i in range(k-1):
        if left <= n-right+1:
            left-=1
        else:
            right+=1
# print(left, ini, right)
    
cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# 1の位置から幅優先探索の要領で進む。
# 余った両辺の長さがなるべく同じようになるように選ぶ
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = k-1
elif n-ini <= k:
    left = n-1 - (k-1)
    right = n-1
else:
    left = ini
    right = ini
    for i in range(k-1):
        if left <= n-right+1:
            left-=1
        else:
            right+=1
# print(left, ini, right)
    
cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# 1の位置から幅優先探索の要領で進む。
# 余った両辺の長さがなるべく同じようになるように選ぶ
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = k-1
elif n-ini <= k:
    left = n-1 - (k-1)
    right = n-1
else:
    left = ini
    right = ini
    for i in range(k-1):
        if left <= n-right-1:
            left-=1
        else:
            right+=1
# print(left, ini, right)
    
cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# 1の位置から幅優先探索の要領で進む。
# 余った両辺の長さがなるべく同じようになるように選ぶ
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = k-1
elif n-ini <= k:
    left = n-1 - (k-1)
    right = n-1
else:
    left = ini
    right = ini
    for i in range(k-1):
        if left <= n-right-1:
            left+=1
        else:
            right+=1
# print(left, ini, right)
    
cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# 1の位置から幅優先探索の要領で進む。
# 余った両辺の長さがなるべく同じようになるように選ぶ
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = ini
elif n-ini < k:
    left = ini
    right = n-1
else:
    left = ini
    right = ini
    for i in range(k-1):
        if left <= n-right-1:
            left+=1
        else:
            right+=1
    
cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# 1の位置から幅優先探索の要領で進む。
# 余った両辺の長さがなるべく同じようになるように選ぶ
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = k-1
elif n-ini < k:
    left = n-1 - (k-1)
    right = n-1
else:
    left = ini
    right = ini
    for i in range(k-1):
        if left <= n-right-1:
            left+=1
        else:
            right+=1
    
cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
# 最小値を含むような、長さkの数列を選択する
# その際、余った長さが最も近くなるような選び方をする
# 2 <= n <= 10**5
n, k = map(int, input().split())
a = list(map(int, input().split()))

ini = a.index(1)
if ini < k:
    left = 0
    right = k-1
else:
    left = ini
    right = ini + (k-1)
    
cnt = 1
if left != 0:
    cnt+=(int(left/(k-1)))
    
if right < n-1:
    cnt+=(int((n-right+1)/(k-1)))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
Alist = list(map(int, input().split()))
split_index = Alist.index(1)
left_l, right_l = split_index, N - split_index - 1
if N <= K:
    print(1)
else:
    print(left_l // (K - 1) + int(left_l % (K - 1) != 0) + right_l // (K - 1) + int(right_l % (K - 1) != 0))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
Alist = list(map(int, input().split()))
split_index = Alist.index(1)
left_l, right_l = split_index, N - split_index - 1
print(left_l, right_l)
if N <= K:
    print(1)
else:
    print(left_l // (K - 1) + int(left_l % (K - 1) != 0) + right_l // (K - 1) + int(right_l % (K - 1) != 0))

Submission status: Wrong Answer

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

m = 10**8
idx = 0
for i in range(N):
    if A[i] < m:
        m = A[i]
        idx = i

cnt = 0
i = idx
while i < N - 1:
    i += K - 1
    cnt += 1
i = idx
while 0 < i:
    i -= K - 1
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ichi=a.index(1) #1の位置(index番号)

ans=float("inf")
#1を含むKの位置をずらしていって最小になるとこを探す…
#端に行き渡らせるまでに、左右それぞれ何回かかるかの式求める。
import math
for i in range(k):
  if ichi-i<0 or ichi+k-i>n-1:
    break
  left=math.ceil((ichi-i)/(k-1)) #左端までかかる回数
  right=math.ceil((n-ichi-(k-i))/(k-1)) #右端までかかる回数
  # print(ichi-i,left,right)
  ans=min(ans,1+left+right)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ichi=a.index(1) #1の位置(index番号)

ans=float("inf")
#1を含むKの位置をずらしていって最小になるとこを探す…
#端に行き渡らせるまでに、左右それぞれ何回かかるかの式求める。
import math
for i in range(k):
  if ichi-i<0 or ichi+k-i>n:
    break
  left=math.ceil((ichi-i)/(k-1)) #左端までかかる回数
  right=math.ceil((n-ichi-(k-i))/(k-1)) #右端までかかる回数
  # print(ichi-i,left,right)
  ans=min(ans,1+left+right)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ichi=a.index(1) #1の位置(index番号)

ans=float("inf")
#1を含むKの位置をずらしていって最小になるとこを探す…
#端に行き渡らせるまでに、左右それぞれ何回かかるかの式求める。
import math
for i in range(k):
  if ichi-i<0 or ichi+k-1-i>n:
    break
  left=math.ceil((ichi-i)/(k-1)) #左端までかかる回数
  right=math.ceil((n-ichi-(k-i))/(k-1)) #右端までかかる回数
  # print(ichi-i,left,right)
  ans=min(ans,1+left+right)
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
ichi=a.index(1) #1の位置(index番号)

ans=float("inf")
#1を含むKの位置をずらしていって最小になるとこを探す…
#端に行き渡らせるまでに、左右それぞれ何回かかるかの式求める。
import math
for i in range(k):
  left=math.ceil((ichi-i)/(k-1)) #左端までかかる回数
  right=math.ceil((n-ichi-(k-i))/(k-1)) #右端までかかる回数
  print(ichi-i,left,right)
  ans=min(ans,1+left+right)
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
idx = A.index(1)
import math
ans = math.ceil(idx/(K-1)) + math.ceil((N-1-idx)/(K-1))
print(ans)

Submission status: Wrong Answer

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    N, K = MI()
    A = LI()
    a = min(A)
    count = []

    tmp = 0
    for i in range(len(A)):
        if A[i] != a:
            tmp += 1
        else:
            if tmp != 0:
                count.append(tmp)
                tmp = 0

    if tmp != 0:
        count.append(tmp)

    ans = 0
    for c in count:
        # print(c, (K-1), math.ceil(float(c) / (K-1)))
        ans += math.ceil(float(c) / (K-1))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
i1=A.index(1)
print(-(-len(A[:i1])//(k-1)) + (-(-len(A[i1+1:])//(k-1))))

Submission status: Wrong Answer

Solution code:
def examC():
    N, K = LI()
    A = LI()
    for i,a in enumerate(A):
        if a==1:
            locate1 = i
            break
    ans = (locate1+K-2)//(K-1) + (N-locate1+K-3)//(K-1)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
ind = A.index(1)
print((ind+K-2)//(K-1) + (N-ind-3+K)//(K-1))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
position = A.index(1)
left = position
right = n - position - 1
#print(left, right)
counter = 0
import math
counter += math.ceil(left / (k - 1))
right -= left % (k-1)
counter += math.ceil(right / (k - 1))
print(counter)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
position = A.index(1)
left = position
right = n - position - 1
print(left, right)
counter = 0
import math
counter += math.ceil(left / (k - 1))
right -= left % (k-1)
counter += math.ceil(right / (k - 1))
print(counter)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
position = A.index(1)
left = position - 1
right = n - position
counter = 0
import math
counter += math.ceil(left / (k - 1))
right -= left % (k-1)
counter += math.ceil(right / (k - 1))
print(counter)

Submission status: Wrong Answer

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

import numpy as np
import sys

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

arg = 0
op_l = 0
while(True):
    arg_new = arg + K - 1
    op_l += 1
    if np.any(A[arg:arg_new+1] == 1):
        last_arg = (arg, arg_new)
        break
    arg = arg_new

if arg_new == N-1:
    print(op_l)
    sys.exit()

arg = N-1
op_r = 0
while(True):
    arg_new = arg - K + 1
    op_r += 1
    if np.any(A[arg_new:arg+1] == 1):
        if (arg_new, arg) == last_arg:
            op_r -= 1
        break
    if arg_new == last_arg[1]+1:
        break
    arg = arg_new

print(op_l+op_r)

Submission status: Wrong Answer

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

import numpy as np
import sys

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

arg = 0
op_l = 0
while(True):
    arg_new = arg + K - 1
    op_l += 1
    if np.any(A[arg:arg_new+1] == 1):
        last_arg = (arg, arg_new)
        break
    arg = arg_new

if arg_new == N-1:
    print(op_l)
    sys.exit()

arg = N-1
op_r = 0
while(True):
    arg_new = arg - K + 1
    op_r += 1
    if np.any(A[arg_new:arg+1] == 1):
        if (arg_new, arg) == last_arg:
            op_r -= 1
        break
    arg = arg_new

print(op_l+op_r)

Submission status: Wrong Answer

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

import numpy as np
import sys

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

arg = 0
op_l = 0
while(True):
    arg_new = arg + K - 1
    op_l += 1
    if np.any(A[arg:arg_new+1] == 1):
        break
    arg = arg_new

if arg_new == N-1:
    print(op_l)
    sys.exit()

arg = N-1
op_r = 0
while(True):
    arg_new = arg - K + 1
    op_r += 1
    if np.any(A[arg_new:arg+1] == 1):
        break
    arg = arg_new

print(op_l+op_r)

Submission status: Wrong Answer

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