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:
first = input().split()
first = [int(a) for a in first]
n = first[0]
k = first[1]
lst = input().split()
lst = [int(a) for a in lst]

min_index = lst.index(min(lst))

lower = min_index // (k - 1)
upper = (n - min_index) // (k - 1)

print (lower + upper)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
if n == k:
    print(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()))
answer=0
ONE=A.index(1)
BONE=FONE=ONE

while sum(A)!=N:
 answer+=1
 fflag=0
 for i in range(K-1):
  if FONE!=0:
   A[FONE-1]=1
   FONE-=1
   fflag=1
  elif FONE==0 and fflag==1:
   break;
  elif BONE!=N-1:
   A[BONE+1]=1
   BONE+=1

print(answer)

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
a = list(map(int,input().split()))
m = 0
for i in range(0,len(a)):
    if a[i] == 1:
        m = i
        break
print(math.ceil((n-1-i)/(k-1)) + math.ceil(i/(k-1)))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
m = 0
for i in range(0,len(a)):
    if a[i] == 1:
        m = i
        break
print((n-i)//(k-1) + i//(k-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in xrange(N):
    if A[i] == 1:
        L, R = i, i
        break

ans = 0
if K - 1 > R:
    L = 0
    R = K - 1
    ans = 1
elif N - K < L:
    L = N - K
    R = N - 1
    ans = 1

while L > 0 or R < N - 1:
    if L > 0:
        L -= K - 1
        ans += 1
    elif R < N - 1:
        R += K - 1
        ans += 1

print ans

Submission status: Wrong Answer

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

for i in xrange(N):
    if A[i] == 1:
        L, R = i, i
        break

ans = 0
if K >= L + 2:
    L = 0
    R = K - 1
    ans = 1
elif K >= N - R + 1:
    L = N - K
    R = N - 1
    ans = 1

while L > 0 or R < N - 1:
    if L > 0:
        L -= K - 1
        ans += 1
    elif R < N - 1:
        R += K - 1
        ans += 1

print ans

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
i = a.index(min(a))
def solve(x, y):
    q1 = (x+k-2)//(k-1)
    r = x%(k-1)
    q2 = max(0, y+k-2-r)//(k-1)
    return q1+q2
x = i
y = n-i-1
print(min(solve(x, y), solve(y, x)))

Submission status: Wrong Answer

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

i = A.index(1)
if i < K or N-K < i:
    ans = (N-1+K-2)//(K-1)
else:
    ans = 0
    while i > 0:
        ans += 1
        i -= K-1
    i = A.index(1)
    while i < N-1:
        ans += 1
        i += K-1
print(ans)

Submission status: Wrong Answer

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

ans = 0
i = A.index(1)
while i > 0:
    ans += 1
    i -= K-1
i = A.index(1)
while i < N-1:
    ans += 1
    i += K-1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
front = A.index(1)
back = N - front - 1
ret = ceil(front/(K-1)) + ceil(back/(K-1))
print(ret)

Submission status: Wrong Answer

Solution code:
# your code goes here
buf = input().split()
n = int(buf[0])
k = int(buf[1])
astr = input().split()
#print(n, k, astr)
print((n-1)//(k-1)+1)

Submission status: Wrong Answer

Solution code:
# your code goes here
buf = input().split()
n = int(buf[0])
k = int(buf[1])
astr = input().split()
#print(n, k, astr)
print(n//(k-1)+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if N == K:
  print(1)
else:
    K = K-1
    ans += (len(a)//K)
    if len(a) % K != 0:
      ans += 1
    print(ans)

Submission status: Wrong Answer

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

if p+1<=K or N-p<=K:
    print(math.ceil((N-1)/(K-1)))
else:
    print(min(math.ceil((p+1)/(K-1))+math.ceil((N-p)/(K-1)),1+math.ceil((2+p-K//2)/(K-1))+math.ceil((N-p-K//2)/(K-1))))

Submission status: Wrong Answer

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

if p+1<=K or N-p<=K:
    print(math.ceil((N-1)/(K-1)))
else:
    print(min(math.ceil((p+1)/(K-1))+math.ceil((N-p)/(K-1)),1+math.ceil((1+p-K//2)/(K-1))+math.ceil((1+N-p-K//2)/(K-1))))

Submission status: Wrong Answer

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

if p+1<=K or N-p<=K:
    print(math.ceil((N-1)/(K-1)))
else:
    print(min(math.ceil((p+1)/(K-1))+math.ceil((N-p)/(K-1)),1+math.ceil((p-(K-1)//2)/(K-1))+math.ceil((N-p-1-(K-1)//2)/(K-1))))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d <= K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex >= 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e <= K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx >= 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  ans3 = 0
  ans4 = 999999999999999999
  V = K-1
  for i in range(K):
    ans3 = 0
    dx = d- i
    ex = e - (K - i - 1)
    ans3 += 1
    if dx > 0:
      if ex > 0:
        ans3 += ex//V
        if ex % V != 0:
          ans3 += 1
        ans3 += ex//V
        if dx % V != 0:
          ans3 += 1
        ans4 = min(ans4,ans3)
  print(min(ans,ans1,ans2,ans4))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d <= K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex >= 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e <= K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx >= 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  ans3 = 0
  ans4 = 999999999999999999
  V = K-1
  for i in range(K):
    ans3 = 0
    dx = d- i -1
    ex = e - (K - i - 1)
    ans3 += 1
    if dx > 0:
      if ex > 0:
        ans3 += ex//V
        if ex % V != 0:
          ans3 += 1
        ans3 += ex//V
        if dx % V != 0:
          ans3 += 1
        ans4 = min(ans4,ans3)
  print(min(ans,ans1,ans2,ans4))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d <= K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex >= 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e <= K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx >= 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  ans3 = 0
  ans4 = 999999999999999999
  V = K-1
  for i in range(K-1):
    ans3 = 0
    dx = d- i 
    ex = e- K - i-1
    if dx > 0:
      if ex > 0:
        ans3 += ex//V
        if ex % V != 0:
          ans3 += 1
        ans3 += ex//V
        if dx % V != 0:
          ans3 += 1
        ans4 = min(ans4,ans3)
  print(min(ans,ans1,ans2,ans4))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d <= K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex >= 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e <= K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx >= 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  ans3 = 0
  ans4 = 999999999999999999
  V = K-1
  for i in range(K-1):
    ans3 = 0
    dx = d- i 
    ex = e- K -1
    if dx > 0:
      if ex > 0:
        ans3 += ex//V
        if ex % V != 0:
          ans3 += 1
        ans3 += ex//V
        if dx % V != 0:
          ans3 += 1
        ans4 = min(ans4,ans3)
  print(min(ans,ans1,ans2,ans4))

Submission status: Wrong Answer

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

if p+1<=K or N-p<=K:
    print(math.ceil((N-1)/(K-1)))
else:
    print(math.ceil(p/(K-1))+math.ceil((N-p-1)/(K-1)))

Submission status: Wrong Answer

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

if p+1<=K or N-p<=K:
    print(math.ceil((N-1)/(K-1)))
else:
    print(math.ceil((p+1)/(K-1))+math.ceil((N-p)/(K-1)))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
min_idx = A.index(1)
if min_idx < K:
    min_idx = K - 1
elif min_idx >= N - K:
    min_idx = N - K
ans = min_idx // (K - 1) + (N - min_idx - 1) // (K - 1)
if min_idx % (K - 1) != 0:
    ans += 1
if (N - min_idx - 1) % (K - 1) != 0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
s=list(input().split())
p=10**6
t=s.index("1")
a=t-1
b=N-t
if K-1<=a or K-1<=b:
    if N==K:
        print(1)
    else:
        print((N-1)//(K-1)+1)
else:
    for i in range(K):
        a=t
        b=N
        a-=i
        b-=K-1-i
        while a%(K-1)!=0:
            a+=1
        while b%(K-1)!=0:
            b+=1
        ans=a//(K-1)+b//(K-1)+1  
        p=min(ans,p)
    print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d <= K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex >= 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e <= K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx >= 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  print(min(ans,ans1,ans2))

Submission status: Wrong Answer

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

if p+1<=K or N-p<=K:
    print(math.ceil((N-1)/(K-1)))
else:
    print((p+1)//(K-1)+(N-p)//(K-1))

Submission status: Wrong Answer

Solution code:
input_line = input().split()

num_array = int(input_line[0])
num_equal = int(input_line[1])

input_line = input()

# from forward

if num_array % num_equal == 0:
    if num_array == num_equal:
        print("1")
    else:
        print(num_array // (num_equal - 1) + 1)

else:
    print(num_array // (num_equal - 1))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, raw_input().split())
    list = map(int, raw_input().split())
    minindex = min(zip(list, range(len(list))))[1]
    if minindex is 0:
        mae = []
    else:
        mae = list[:minindex]
    if minindex is len(list)-1:
        ato = []
    else:
        ato = list[minindex+1:]
    if len(mae)%(K-1) is 0:
        maetime = len(mae)/(K-1)
    else:
        maetime = len(mae)/(K-1) + 1
    if len(ato)%(K-1) is 0:
        atotime = len(ato)/(K-1)
    else:
        atotime = len(ato)/(K-1) + 1
    if len(mae)%(K-1) + len(ato)%(K-1) >= K-1:
        print maetime+atotime-1
    else:
        print maetime+atotime

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d < K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex > 0:
      V = K-1
      ans1 += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e < K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx > 0:
      V = K-1
      ans2 += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  print(min(ans,ans1,ans2))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0

k = (a[0] - 1) // (a[1] - 1)
 
if a[0] != a[1]:
	k += 1


print(k)

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, raw_input().split())
    list = map(int, raw_input().split())
    minindex = min(zip(list, range(len(list))))[1]
    if minindex is 0:
        mae = []
    else:
        mae = list[:minindex]
    if minindex is len(list)-1:
        ato = []
    else:
        ato = list[minindex+1:]
    if len(mae)%(K-1) is 0:
        maetime = len(mae)/(K-1)
    else:
        maetime = len(mae)/(K-1) + 1
    if len(ato)%(K-1) is 0:
        atotime = len(ato)/(K-1)
    else:
        atotime = len(ato)/(K-1) + 1
    if len(mae)%(K-1) + len(ato)%(K-1) is K-1:
        print maetime+atotime-1
    else:
        print maetime+atotime

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, raw_input().split())
    list = map(int, raw_input().split())
    minindex = min(zip(list, range(len(list))))[1]
    if minindex is 0:
        mae = []
    else:
        mae = list[:minindex]
    if minindex is len(list)-1:
        ato = []
    else:
        ato = list[minindex+1:]
    print mae
    print ato
    if len(mae)%(K-1) is 0:
        maetime = len(mae)/(K-1)
    else:
        maetime = len(mae)/(K-1) + 1
    if len(ato)%(K-1) is 0:
        atotime = len(ato)/(K-1)
    else:
        atotime = len(ato)/(K-1) + 1
    if len(mae)%(K-1) + len(ato)%(K-1) is K-1:
        print maetime+atotime-1
    else:
        print maetime+atotime

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(a[0]):
	if b[i] == 1:
		c = i

k = (a[0] + 1) // (a[1] - 1)

if a[0] == a[1]:
	k -= 1

print(k)

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
x = a.index(1)

def calc(x):
    return x / (k-1) + (x % (k-1) != 0)

print calc(x) + calc(n-x-1)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d < K-1:
    ans1 += 1
    ex = e -(K-d-1)
    if ex > 0:
      V = K-1
      ans += ex // V
      if ex % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e < K-1:
    ans2 += 1
    dx = d -(K-e-1)
    if dx > 0:
      V = K-1
      ans += dx // V
      if dx % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  print(min(ans,ans1,ans2))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(a[0]):
	if b[i] == 1:
		c = i
k = (a[0]) // (a[1] - 1)
 
if a[0] == a[1]:
	k += 1
print(k)

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
pos_1 = A.index(1)
former = pos_1
latter = N - 1 - pos_1
ans = 0
s = min(former, latter)
l = max(former, latter)
if N == K:
  ans = 1
elif s < K:
  ans += 1
  l -= K - s - 1
  ans += l // (K - 1)
  if l % (K - 1) != 0:
    ans += 1
else:
  ans += s // (K - 1)
  if s % (K - 1) != 0:
    ans += 1
  ans += l // (K - 1)
  if l % (K - 1) != 0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  ans1 = 0
  ans2 = 0
  if d < K-1:
    ans1 += 1
    e = e -(K-d-1)
    if e < 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans1 += 1
  else:
    ans1 = 999999999999999999999999999999
  if e < K-1:
    ans2 += 1
    d = d -(K-e-1)
    if d < 0:
      V = K-1
      ans += d // V
      if e % V != 0:
        ans2 += 1
  else:
    ans2 = 999999999999999999999999999999
  print(min(ans,ans1,ans2))

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
pos_1 = A.index(1)
former = pos_1
latter = N - 1 - pos_1
ans = 0
s = min(former, latter)
l = max(former, latter)
if s < K:
  ans += 1
  l -= K - s - 1
  ans += l // (K - 1)
  if l % (K - 1) != 0:
    ans += 1
else:
  ans += s // (K - 1)
  if s % (K - 1) != 0:
    ans += 1
  ans += l // (K - 1)
  if l % (K - 1) != 0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


# def kiriage(a, b):
#     return (a + b - 1) // b


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    i = A.index(1)

    # print(kiriage(i, K-1) + kiriage(N-i-1, K-1))
    l = i // (K-1)
    r = (N-i-1) // (K-1)

    rest_left = i - l*(K-1)
    rest_right = (N-i-1) - r*(K-1)
    rest = N - (l+r) * (K-1)


    if rest_left == 0 and rest_right == 0:
        print(l+r)
    elif rest_left == 0 or rest_right == 0:
        print(l+r+1)
    elif rest <= K-3:
        print(l + r + 1)
    else:
        print(l+r+2)

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n):
    if a[i]==1:
        mi=i
x=n-(mi+1)#最小値から右側
y=mi#最小値から左側
if x%(k-1)==0:
    ax=x//(k-1)
else:
    ax=x//(k-1)+1
if y%(k-1)==0:
    ay=y//(k-1)
else:
    ay=y//(k-1)+1
if x%(k-1)!=0 and y%(k-1)!=0:
    if 0<x%(k-1)+y%(k-1)<k:
        print(ax+ay-1)
else:
    print(ax+ay)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
k=int(input().split()[1])-1
s=input().split()
l=[int(item) for item in s]
ind=l.index(1)
p,q=ind,len(l)-ind-1
if p<k or q<k:
    print(math.ceil(1+(len(l)-k-1)/k))
else:
    print(math.ceil(p/k)+math.ceil(q/k))

Submission status: Wrong Answer

Solution code:
import math
N, K = [int(i) for i in input().split()]
a = list(map(int, input().split()))

pos = int(a.index(1))

if min(pos+1,N-pos)<K:
  ans = math.ceil((N-K)/(K-1))+1
else:
  ans = math.ceil((pos+1-K)/(K-1))+1 + math.ceil((N-pos-K)/(K-1))+1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, A):
    for i, a in enumerate(A):
        if a == 1:
            break

    l = A[:i]
    r = A[i+1:]
    ans = 0
    ans += math.ceil(len(l) / (K-1))
    ans += math.ceil(len(r) / (K-1))

    if ((K-1) - len(l) % (K-1)) + ((K-1) - len(r) % (K-1)) <= (K-1):
        ans -= 1

    return ans


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n):
    if a[i]==1:
        mi=i
x=n-(mi+1)#最小値から右側
y=mi#最小値から左側
if x%(k-1)==0:
    ax=x//(k-1)
else:
    ax=x//(k-1)+1
if y%(k-1)==0:
    ay=y//(k-1)
else:
    ay=y//(k-1)+1
if 0<x%(k-1)+y%(k-1)<k:
    print(ax+ay-1)
else:
    print(ax+ay)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
array = [int(x) for x in input().split()]

tmp = array.index(1)

if tmp == 0:
    res1 = 0
    res2 = math.ceil((n-1)/(k-1))
elif tmp == n-1:
    res1 = math.ceil((n-1)/(k-1))
    res2 = 0
else:
    res1 = math.ceil((tmp)/(k-1))
    res2 = math.ceil((n-tmp-1)/(k-1))

print(res1+res2)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
P1=0
for i in range(N):
    if A[i]==1:
        P1=i
        break
L=P1
R=N-1-P1
if L>=K-1 and R>=K-1:
    print(-((-L)//(K-1))-((-R)//(K-1)))
else:
    print(-((1-N)//(K-1)))

Submission status: Wrong Answer

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

if k == n:
	print(1)
elif 2 * k > n:
	print(2)
else:
	one_index = a.index(1)

	if one_index == 0 or one_index == n - 1:
		print((n - 2) // (k - 1) + 1)
	elif one_index <= k - 1 or n - one_index - 1 <= k - 1:
		print((n - 2) // (k - 1) + 1)
	else:
		print((one_index - 1) // (k - 1) + (n - one_index - 2) // (k - 1) + 2)

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, input().split())
array = [int(x) for x in input().split()]

tmp = array.index(1)

if tmp == 0:
    res1 = 0
    res2 = math.ceil((n-1)/(k-1))
elif tmp == n-1:
    res1 = math.ceil((n-1)/(k-1))
    res2 = 0
else:
    res1 = math.ceil((tmp)/(k-1))
    res2 = math.ceil((n-tmp-1)/(k-1))

print(res1,res2)

Submission status: Wrong Answer

Solution code:

N, K = [int(a) for a in input().split()]
ans = (N-1) // (K-1) + 1
print(str(ans))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    V = K-1
    ans += d // V
    if d % V != 0:
      ans += 1
  e = N-1-c
  if e != 0:
      V = K-1
      ans += e // V
      if e % V != 0:
        ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


# def kiriage(a, b):
#     return (a + b - 1) // b


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    i = A.index(1)

    # print(kiriage(i, K-1) + kiriage(N-i-1, K-1))
    l = i // (K-1)
    r = (N-i-1) // (K-1)

    rest_left = i - l*(K-1)
    rest_right = (N-i-1) - r*(K-1)
    rest = N - (l+r) * (K-1)


    if rest_left == 0 and rest_right == 0:
        print(l+r)
    elif rest_left == 0 or rest_right == 0:
        print(l+r+1)
    elif rest <= K-2:
        print(l + r + 1)
    else:
        print(l+r+2)

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(a[0]):
	if b[i] == 1:
		c = i
k = (a[0] + 1) // (a[1] - 1)
 
if a[0] == a[1]:
	k -= 1

if c >= a[1] and c <= a[0] - a[1]:
	k += 1

print(k)

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
pos_1 = A.index(1)
former = pos_1
latter = N - 1 - pos_1
ans = 0
ans += former // (K - 1)
if former % (K - 1) != 0 and former > 0:
  ans += 1
ans += latter // (K - 1)
if latter % (K - 1) != 0:
  ans += 1
print(ans)

Submission status: Wrong Answer

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

minIndex = a.index(1)

nowi = minIndex
count = 0
while nowi > 0:
    nowi -= k + 1
    count += 1

nowi = minIndex
while nowi < n - 1:
    nowi += k - 1
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
c = a.index(1)
naga = len(a)-K
if naga <= 0:
  print(1)
else:
  d = c-0
  if d != 0:
    if d <= K:
      ans+=1
    else:
      V = K-1
      ans += d // V +1
  e = N-1-c
  if e != 0:
    if e <= K:
      ans+=1
    else:
      V = K-1
      ans += e // V +1
  print(ans)

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
pos_1 = A.index(1)
former = pos_1 - 1
latter = N - 1 - pos_1
ans = 0
ans += former // (K - 1)
if former % (K - 1) != 0 and former > 0:
  ans += 1
ans += latter // (K - 1)
if latter % (K - 1) != 0:
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


# def kiriage(a, b):
#     return (a + b - 1) // b


if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    i = A.index(1)

    # print(kiriage(i, K-1) + kiriage(N-i-1, K-1))
    l = i // (K-1)
    r = (N-i-1) // (K-1)

    rest_left = i - l*(K-1)
    rest_right = (N-i-1) - r*(K-1)
    rest = N - (l+r) * (K-1)


    if rest_left == 0 and rest_right == 0:
        print(l+r)
    elif rest_left == 0 or rest_right == 0:
        print(l+r+1)
    elif rest <= N-2:
        print(l + r + 1)
    else:
        print(l+r+2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, raw_input().split())
    list = map(int, raw_input().split())
    minindex = min(zip(list, range(len(list))))[1]
    # print minindex
    if minindex is 0:
        mae = []
    else:
        mae = list[:minindex-1]
    if minindex is len(list)-1:
        ato = []
    else:
        ato = list[minindex+1:]
    # print(ato)
    if len(mae)%(K-1) is 0:
        maetime = len(mae)/(K-1)
    else:
        maetime = len(mae)/(K-1) + 1
    if len(ato)%(K-1) is 0:
        atotime = len(ato)/(K-1)
    else:
        atotime = len(ato)/(K-1) + 1
    print maetime+atotime

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if k == n:
	print(1)
elif 2 * k > n:
	print(2)
else:
	one_index = a.index(1)

	if one_index == 0 or one_index == n - 1:
		print((n - 2) // (k - 1) + 1)
	elif one_index < k - 1 or n - one_index - 1 < k - 1:
		print((n - 2) // (k - 1) + 1)
	else:
		print((one_index - 1) // (k - 1) + (n - one_index - 2) // (k - 1) + 2)

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
pos_1 = A.index(1)
former = pos_1 - 1
latter = N - 1 - pos_1
ans = 0
ans += former // (K - 1)
if former % (K - 1) != 0:
  ans += 1
ans += latter // (K - 1)
if latter % (K - 1) != 0:
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, K = [int(i) for i in input().split()]
a = list(map(int, input().split()))

pos = a.index(1)

if min(pos+1,N-pos)<K:
  ans = math.ceil((N-K)/(K-1))+1
else:
  ans = math.ceil((pos+1-K)/(K-1))+1 + math.ceil((N-pos-K)/(K-1))+1
print(ans)