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:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n,k = MI()
a = RI()

ind = a.index(1)
ans = 0

if ind>(k-1) and ind<(n-k):
    ans += ceil(ind/(k-1))
    ans += ceil((n-1-ind)/(k-1))
elif ind<=(k-1):
    ans += ceil((n-k)/(k-1)) + 1
else:
    ans += ceil((n-k)/(k-1)) + 1

print(ans)

Submission status: Wrong Answer

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

i = a.index(1)

s = n

for j in range(i-k+1, i+1):
    if j < 0:
        continue
    elif j >= n:
        continue
    else:
        l = j
        u = (n-1-j)
        t = (l+1) // (k-1) + (u+1) // (k-1)
        #print(t)
        s = min(s, t)

print(s)

Submission status: Wrong Answer

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

i = a.index(1)

s = n

for j in range(i-k+1, i+k):
    if j < 0:
        continue
    elif j >= n:
        continue
    else:
        l = j
        u = (n-1-j)
        t = (l+1) // (k-1) + (u+1) // (k-1)
        #print(t)
        s = min(s, t)

print(s)

Submission status: Wrong Answer

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

i = a.index(1)

s = n

for j in range(i-k+1, i+k):
    l = j
    u = (n-1-j)
    t = (l+1) // (k-1) + (u+1) // (k-1)
    s = min(s, t)

print(s)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = A.index(1)
#print(B)
ans = 0
C = B
if K == N:
    print(1)
else:
    print(N//(K-1))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = A.index(1)
#print(B)
ans = 0
C = B
if K == N:
    print(1)
else:
    while C < N:
        C += K - 1
        ans += 1
    while B > 0:
        B -= K - 1
        ans += 1
    print(ans)

Submission status: Wrong Answer

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

l = one_index
r = n - 1 - one_index

res = (l + (k - 1 - 1)) // (k - 1) + (r + (k - 1 - 1)) // (k - 1)
if n <= k:
    print(1)
else:
    print(res)

Submission status: Wrong Answer

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

l = one_index
r = n - 1 - one_index

res = (l + (k - 1 - 1)) // (k - 1) + (r + (k - 1 - 1)) // (k - 1)
print(res)

Submission status: Wrong Answer

Solution code:

N,K = map(int,input().split())
A = list(map(int,input().split()))
if N==K:
    print(1)
    exit(0)
index = A.index(1)

ans = (N-1-index+K-2)//(K-1) + (index+K-2)//(K-1)

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

m = n-k
if n>k:
  print(m//(k-1) + 2)
else:
  print(m//(k-1) + 1)

Submission status: Wrong Answer

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

if n>k:
  print((n+1)//k+1)
else:
  print(1)

Submission status: Wrong Answer

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

if min(a) == a[0] or min(a) == a[n-1]:
  print((n+1)//k)
else:
  print((n+1)//k + 1)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

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

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

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

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

idx = 0
for i in range(N):
    if A[i] == 1:
        idx = i
        break

ans = N
for k in range(K):
    temp = 1
    l = max(idx - k, 0)
    r = min(l + K - 1, N - 1)

    if l == 0:
        num_l = 0
    else:
        num_l = l + 1

    if num_l == K:
        temp += 1
    else:
        temp += ceil(num_l / (K - 1))

    if r == N - 1:
        num_r = 0
    else:
        num_r = N - r

    if num_r == K:
        temp += 1
    else:
        temp += ceil(num_r / (K - 1))

    ans = min(ans, temp)


print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

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

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

idx = 0
for i in range(N):
    if A[i] == 1:
        idx = i
        break

ans = N
for k in range(K):
    temp = 1
    l = max(idx - k, 0)
    r = min(l + K - 1, N - 1)

    if l == 0:
        num_l = 0
    else:
        num_l = l + 1

    if num_l == K:
        temp += 1
    else:
        temp += ceil(num_l / (K - 1))

    if r == N - 1:
        num_r = 0
    else:
        num_r = N - r

    if num_r == K:
        temp += 1
    else:
        temp += ceil(num_r / (K - 1))

    ans = min(ans, temp)

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

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

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

idx = 0
for i in range(N):
    if A[i] == 1:
        idx = i
        break

cnt = 0
if idx + 1 == K:
    cnt += 1
else:
    cnt += ceil((idx + 1) / (K - 1))

if N - idx == K:
    cnt += 1
else:
    cnt += ceil((N - idx) / (K - 1))

print(cnt)

Submission status: Wrong Answer

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

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

q, r = divmod(N, K - 1)

if r == 0:
    print(q)
else:
    print(q + 1)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    As = list(map(int, input().split()))
    for i in range(n):
        if As[i] == 1:
            index = i
    left = index + 1
    right = n - index
    ans = 0
    if left == 1:
        ans += 0
    elif left <= k:
        ans += 1
    else:
        ans += left // k + 1

    if right == 0:
        ans += 0
    elif right <= k:
        ans += 1
    else:
        ans += right // 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()))

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

n = n+1    

def main(M,P):
  cnt = 1
  while True:
    M -= P
    M += 1
    if M > P:
      cnt += 1
    if M == 0:
      break
    if M != 0 and P > M:
      cnt += 1
      break
  return cnt

if N == K:
  print("1")
  
elif K >= n :
  print(main(N,K))
  
else :
  N1 = n-1
  N2 = N-n
  print(main(N1,K)+main(N2,K))

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:
    n = i

n = n+1    

def main(M,P):
  cnt = 1
  while True:
    M -= P
    M += 1
    if M > P:
      cnt += 1
    if M == 0:
      break
    if M != 0 and P > M:
      cnt += 1
      break
  return cnt

if N == K:
  print("1")
  
elif K >= n :
  print(main(N,K))
  
else :
  N1 = n
  N2 = N-n+1
  print(main(N1,K)+main(N2,K))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    index_1 = A.index(1)
    left = (index_1 + k - 2) // (k - 1)
    right = (n - 1 - index_1 + k - 2) // (k - 1)
    print(left + right)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

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

p = 0
for i in range(n):
    if aa[i] == 1:
        p = i
        break

x = 0
k -= 1
x += math.ceil(p / k)
x += math.ceil((n - p - 1) / k)
print(x)

Submission status: Wrong Answer

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

p = a.index(1)
ans = ceil(p/(k-1))
ans += ceil((n-1-p)/(k-1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *A = map(int, read().split())

    print(N // (K - 1))

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math

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

index = a.index(1)

pre = index
post = n-index-1

post = max(post - pre % (k-1), 0)

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math

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

index = a.index(1)

pre = index
post = n-index-1

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

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
List = list(map(int, input().split()))
k=K-1
n = (N-1)/k
nn = int(n)
if n-nn > 0:
  n = nn+1
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

P = K - 1
print(N // P)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = (n-1)/(k-1)#切り上げ
if ans % 1 == 0:
  print(int(ans))
else:
  print(ans // 1 + 1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=10**9
ix=a.index(1)
ans=math.ceil(ix/(k-1))+math.ceil((n-ix-1)/(k-1))
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=(int(i) for i in input().strip().split(" "))
ar=[int(i) for i in input().strip().split(" ")]
from math import ceil
pos=ar.index(1)
a=n-1-pos
b=pos
ans=ceil(a/(k-1))
ans+=ceil(b/(k-1))
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=(int(i) for i in input().strip().split(" "))
ar=[int(i) for i in input().strip().split(" ")]
from math import ceil
pos=ar.index(1)
a=n-1-pos
b=pos
ans=ceil(a/(k-1))
ans+=ceil(b/(n-1))
print(ans)

Submission status: Wrong Answer

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

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

if n==k:
    print(1)
    exit()
    
x = n//(k-1)
y = n%(k-1)

if y >0:
    print(x+1)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
N,K = list(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 K == N:
  print(1)
  exit()
  
MIN = min(A)

argmin=[]
for i in range(N):
  if A[i]==MIN:argmin.append(i)
    
ans = 10**9
for a in argmin:
  SUM=0
  SUM += (a+(K-2)) // (K-1)
  SUM += ((N-1-a)+(K-2))//(K-1)
  if ans > SUM:ans=SUM

print(ans)

Submission status: Wrong Answer

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

if K == N:
  print(1)
  exit()
  
MIN = min(A)

argmin=[]
for i in range(N):
  if A[i]==MIN:argmin.append(i)
    
a = argmin[0]
SUM=0
SUM += (a+(K-2)) // (K-1)
SUM += ((N-1-a)+(K-2))//(K-1)

print(SUM)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
c = input()
print((a+b-1)//b)

Submission status: Wrong Answer

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,K = MI()
A = LI()

i = A.index(1)
j = N-1-i
print((i+1)//2 + (j+1)//2)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

mi = A.index(1)
lc = math.ceil(mi/(K-1))
rc = math.ceil((N-mi-1)/(K-1))

print(lc+rc)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

mi = A.index(1)
lc = math.ceil(mi/2)
rc = math.ceil((N-mi-1)/2)

print(lc+rc)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

mi = A.index(1)
lc = math.ceil(mi//2)
rc = math.ceil((N-mi-1)//2)

print(lc+rc)

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

mi = A.index(1)
lc = (mi+1)//2
rc = (N-mi)//2

print(lc+rc)

Submission status: Wrong Answer

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

#print(A)
count = 0
mn = 10**10
for i in range(0,N-K+2,K-1):
    
    A = A[:i] + [min(A[i:i+K])]*K+A[i+3:]
    count += 1
    if len(list(set(A))) == 1:
        print(count)
        sys.exit()

Submission status: Wrong Answer

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

b = a.index(1) 
if b < k-1:
    b += k-1 -b
if b > (n-1) -(k-1):
    b -= b - (k-1)
c,d = divmod(b,k-1)
ans = c
rem = d
if d != 0:
    ans +=1
e = n-1 -b
c,d = divmod(e,k-1)
ans += c
if d != 0:
    ans +=1
if rem + d <= k-1 and rem != 0 or d != 0:
    ans -=1
print(ans)

Submission status: Wrong Answer

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

b = a.index(1) 
if b < k-1:
    b += k-1 -b
if b > (n-1) -(k-1):
    b -= b - (k-1)
c,d = divmod(b,k-1)
ans = c
rem = d
if d != 0:
    ans +=1
e = n-1 -b
c,d = divmod(e,k-1)
ans += c
if d != 0:
    ans +=1
if rem + d <= k-1:
    ans -=1
print(ans)

Submission status: Wrong Answer

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

b = a.index(1) 
if b < k-1:
    b += k-1 -b
if b > (n-1) -(k-1):
    b -= b - (k-1)
c,d = divmod(b,k-1)
ans = c
if d != 0:
    ans +=1
e = n-1 -b
c,d = divmod(e,k-1)
ans += c
if d != 0:
    ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
if n == k:
    print(1)
else:
    b = a.index(1) 
    if b < k-1:
        b +=1
    if b > (n-1) -k-1:
        b -=1
    c,d = divmod(b,k-1)
    ans = c
    if d != 0:
        ans +=1
    
    
    e = n-1 -b
    c,d = divmod(e,k-1)
    ans += c
    if d != 0:
        ans +=1
    print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
if n == k:
    print(1)
else:
    b = a.index(1)
    c,d = divmod(b,k-1)
    ans = c
    if d != 0:
        ans +=1
    e = n-1 -b
    c,d = divmod(e,k-1)
    ans += c
    if d != 0:
        ans +=1
    print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
b = a.index(1)
c,d = divmod(b,k-1)
ans = c
if d != 0:
    ans +=1
e = n-1 -b
c,d = divmod(e,k-1)
ans += c
if d != 0:
    ans +=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
# abc101_c.py
# https://atcoder.jp/contests/abc101/tasks/arc099_a

# C - Minimization /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 長さ Nの数列 A1,A2,...,AN があります．最初，この数列の要素は 1,2,...,Nを並び替えたものになっています．
# スヌケ君は，この数列に対して次の操作を行うことができます．
#     数列のうち，連続した K個の要素を選ぶ．その後，選んだ要素それぞれの値を，選んだ要素の中の最小値で置き換える．
#     スヌケ君は，上の操作を何回か繰り返すことで，この数列の要素をすべて等しくしたいです． 必要な操作の回数の最小値を求めてください． 
#     この問題の制約の下，このようなことは必ず可能であることが証明できます．

# 制約
#     2≤K≤N≤100000
#     A1,A2,...,ANは 1,2,...,Nの並び替え

# 入力
# 入力は以下の形式で標準入力から与えられる．
# N K
# A1 A2 ... AN

# 出力
# 必要な操作の回数の最小値を出力せよ．

# 入力例 1
# 4 3
# 2 3 1 4

# 出力例 1
# 2

# 例えば，次のようにするとよいです：
#     1回目の操作では，1,2,3 番目の要素を選ぶ．すると，数列 A は 1,1,1,4になる．
#     2回目の操作では，2,3,4 番目の要素を選ぶ．すると，数列 A は 1,1,1,1になる．

# 入力例 2
# 3 3
# 1 2 3

# 出力例 2
# 1

# 入力例 3
# 8 3
# 7 3 1 8 4 6 2 5

# 出力例 3
# 4


def calculation(lines):
    N, K = map(int, lines[0].split(' '))
    values = [value for value in map(int, lines[1].split(' '))]
    # NとKが一致するとExit
    if N == K:
        result = 1
    else:
        for i in range(len(values)):
            if values[i] == 1:
                pos = i
        mae = pos
        ato = N - mae - 1
        # print(f'mae=[{mae}]')
        # print(f'ato=[{ato}]')
        # print((-(-mae//(K-1))))
        # print((-(-ato//(K-1))))
        result = (-(-mae//(K-1))) + (-(-ato//(K-1)))
    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4 3', '2 3 1 4']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['3 3', '1 2 3']
        lines_export = [1]
    if pattern == 3:
        lines_input = ['8 3', '7 3 1 8 4 6 2 5']
        lines_export = [4]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# abc101_c.py
# https://atcoder.jp/contests/abc101/tasks/arc099_a

# C - Minimization /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 長さ Nの数列 A1,A2,...,AN があります．最初，この数列の要素は 1,2,...,Nを並び替えたものになっています．
# スヌケ君は，この数列に対して次の操作を行うことができます．
#     数列のうち，連続した K個の要素を選ぶ．その後，選んだ要素それぞれの値を，選んだ要素の中の最小値で置き換える．
#     スヌケ君は，上の操作を何回か繰り返すことで，この数列の要素をすべて等しくしたいです． 必要な操作の回数の最小値を求めてください． 
#     この問題の制約の下，このようなことは必ず可能であることが証明できます．

# 制約
#     2≤K≤N≤100000
#     A1,A2,...,ANは 1,2,...,Nの並び替え

# 入力
# 入力は以下の形式で標準入力から与えられる．
# N K
# A1 A2 ... AN

# 出力
# 必要な操作の回数の最小値を出力せよ．

# 入力例 1
# 4 3
# 2 3 1 4

# 出力例 1
# 2

# 例えば，次のようにするとよいです：
#     1回目の操作では，1,2,3 番目の要素を選ぶ．すると，数列 A は 1,1,1,4になる．
#     2回目の操作では，2,3,4 番目の要素を選ぶ．すると，数列 A は 1,1,1,1になる．

# 入力例 2
# 3 3
# 1 2 3

# 出力例 2
# 1

# 入力例 3
# 8 3
# 7 3 1 8 4 6 2 5

# 出力例 3
# 4


def calculation(lines):
    N, K = map(int, lines[0].split(' '))
    values = [value for value in map(int, lines[1].split(' '))]
    # NとKが一致するとExit
    if N == K:
        result = 1
    else:
        for i in range(len(values)):
            if values[i] == 1:
                pos = i
        mae = pos
        ato = N - mae - 1
        print(f'mae=[{mae}]')
        print(f'ato=[{ato}]')
        print((-(-mae//(K-1))))
        print((-(-ato//(K-1))))
        result = (-(-mae//(K-1))) + (-(-ato//(K-1)))
    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['4 3', '2 3 1 4']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['3 3', '1 2 3']
        lines_export = [1]
    if pattern == 3:
        lines_input = ['8 3', '7 3 1 8 4 6 2 5']
        lines_export = [4]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')


# 起動処理
if __name__ == '__main__':
    main()

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, raw_input().split())
print (n + k - 1)/k

Submission status: Wrong Answer

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

# print(N)
# print(K)
# print(A)

min_index = A.index(min(A))
# print(min_index)

leftLength = min_index
rightLength = N - 1 - leftLength
# print(leftLength)
# print(rightLength)

delta = K - 1
# print(delta)

count = 0
leftTimes = leftLength // delta
remain = leftLength % delta
if remain > 0:
    leftTimes = leftTimes + 1
    rightLength = rightLength - remain

if rightLength <= 0:
    print(leftTimes)
else:
    rightTimes = rightLength // delta
    remain = rightLength % delta
    if remain > 0:
        rightTimes = rightTimes + 1

    count = leftTimes + rightTimes

    print(count)

Submission status: Wrong Answer

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

# print(N)
# print(K)
# print(A)

min_index = A.index(min(A))
# print(min_index)

leftLength = min_index
rightLength = N - 1 - leftLength
# print(leftLength)
# print(rightLength)

delta = K - 1
# print(delta)

count = 0
leftTimes = leftLength // delta
remain = leftLength % delta
if remain > 0:
    leftTimes = leftTimes + 1
    rightLength = rightLength - remain

rightTimes = rightLength // delta
remain = rightLength % delta
if remain > 0:
    rightTimes = rightTimes + 1

count = leftTimes + rightTimes

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    i_min = A.index(1)
    ans = -(-i_min // (k - 1)) -(-(n - i_min - 1) // (k - 1))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K = (int(X) for X in input().split())
A  = [int(X) for X in input().split()]
Left  = A.index(1)
Right = (N-1)-Left
Count = (Right%(K-1)!=0)+Right//2
Left  = max(0,Left-Right%(K-1))
Count += (Left%(K-1)!=0)+Left//2
print(Count)

Submission status: Wrong Answer

Solution code:
N,K = (int(X) for X in input().split())
A  = [int(X) for X in input().split()]
Left  = A.index(1)
Right = (N-1)-Left
Count = (Right%(K-1)!=0)+Right//2
Left  -= min(0,Right%(K-1))
Count += (Left%(K-1)!=0)+Left//2
print(Count)

Submission status: Wrong Answer

Solution code:
N,K = (int(X) for X in input().split())
A  = [int(X) for X in input().split()]
Left  = A.index(1)
Right = (N-1)-Left
Count = (Right%(K-1)!=0)+Right//2
Left  -= Right%(K-1)
Count += (Left%(K-1)!=0)+Left//2
print(Count)

Submission status: Wrong Answer

Solution code:
n, k = [ int(x) for x in input().split(' ') ]
xs = [  int(x) for x in input().split(' ') ]
i0 = xs.index(min(xs))
print(1 + min([ (i + k - 2) // (k - 1) + (n - i - 1) // (k - 1)
  for i in range(max(i0 - k + 1, 0),  min(i0, 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())
s = list(map(int, input().split()))
m = n//k
count = m*(m+1)//2
print(count+1 if n%k else count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def solve(N: int, K: int, A: "List[int]"):
    from math import ceil
    m = min(A)
    B = [float("inf") if a != m else 0 for a in A]
    for i in range(len(B)-1, 0, -1):
        B[i-1] = min(B[i] + 1, B[i-1])
    k, i = 1, K-1
    while i < N-1:
        i += K if B[i+1] <= K else K-1
        k += 1
    return k

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()