Problem:


Score : 300 points

Problem Statement

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

On this sequence, Snuke can perform the following operation:

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

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

Constraints

2 \leq K \leq N \leq 100000

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

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

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

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

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4



Sample input:
4 3
2 3 1 4


Sample output:
2

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(k-1,n+1):
    if i % (k-1) == 1:
        if i == n:
            break
        n += 1

print(math.ceil(n/k))

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(2,n+1):
    if i % 2 == 1:
        if i == n:
            break
        n += 1

print(math.ceil(n/3))

Submission status: Wrong Answer

Solution code:
import math
N,K = map(int,input().split(' '))
A = 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()))
x = min(a)
b = a.index(min(a))
ans = -(-b//(k-1)) + -(-(n-b-1)//(k-1))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n ,k = I2()
    a = Intl()
    #minは1なのである要素から1までの距離を考えて、それをk-1で割った商が置き換え回数
    cnt = 0
    r = a.index(1)
    first = r#先頭から1までの距離
    end = n-r-1#末尾から1までの距離
    #print(first,end)
    cnt += math.ceil(first/(k-1))
    cnt += math.ceil(end/(k-1))
    print(cnt)

Submission status: Wrong Answer

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

    if (b-ans*(K-1)-1)%(K-1)!=0:
        ans+=(b-ans*(K-1)-1)//(K-1)+1
    else:
        ans+=(b-ans*(K-1)-1)//(K-1)
    
print(ans)

Submission status: Wrong Answer

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

if (b-a-1)%(K-1)!=0:
    ans+=(b-a-1)//(K-1)+1
else:
    ans+=(b-a-1)//(K-1)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = list(map(int, input().split()))
if sum(l) == len(l):
  print(0)
elif n==k:
  print(1)
else:
  print((n+k-2)//(k-1))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = list(map(int, input().split()))
if sum(l) == len(l):
  print(0)
elif n==k:
  print(1)
else:
  print((n+k-1)//k)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = list(map(int, input().split()))
if sum(l) == len(l):
  print(0)
else:
  print((n+k-1)//k)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
x = a.index(1)
if n == k:
    print(1)
    sys.exit()
if x%(k-1)==0 and (n-x-1)%(k-1)==0:
    print(x//(k-1) + (n-x-1)//(k-1))
elif (x%(k-1)==0 and (n-x-1)%(k-1)!=0) or (x%(k-1)!=0 and (n-x-1)%(k-1)==0):
    print(x//(k-1)+(n-x-1)//(k-1)+1)
else:
    print(x//(k-1)+(n-x-1)//(k-1)+(n-x-1))

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
x = a.index(1)
if n == k:
    print(1)
    sys.exit()
if x%(k-1)==0 and (n-x-1)%(k-1)==0:
    print(x//(k-1) + (n-x-1)//(k-1))
elif (x%(k-1)==0 and (n-x-1)%(k-1)!=0) or (x%(k-1)!=0 and (n-x-1)%(k-1)==0):
    print(x//(k-1)+(n-x-1)//(k-1)+1)
else:
    print(x//(k-1)+(n-x-1)//(k-1)+2)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
x = a.index(1)
if n == k:
    print(1)
    sys.exit()
if x%(k-1)==0 and (n-x-1)%(k-1)==0:
    print(x//(k-1) + (n-x-1)//(k-1))
elif (x%(k-1)==0 and (n-x-1)%(k-1)!=0) or (x%(k-1)!=0 and (n-x-1)%(k-1)==0):
    print(x//(k-1)+(n-x-1)//(k-1)+1)
else:
    print(x//(k-1)+(n-x-1)//(k-1)+1)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
x = a.index(1)
if n == k:
    print(1)
    sys.exit()
if x%(k-1)==0 and (n-x-1)%(k-1)==0:
    print(x//(k-1) + (n-x-1)//(k-1))
elif (x%(k-1)==0 and (n-x-1)%(k-1)!=0) or (x%(k-1)!=0 and (n-x-1)%(n-k)==0):
    print(x//(k-1)+(n-x-1)//(k-1)+1)
else:
    print(x//(k-1)+(n-x-1)//(k-1)+1)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,k=I()
a = l()
x = a.index(1)
if n == k:
    print(1)
    sys.exit()
if x % (k-1)==0 and (n-x-1)%(k-1)==0:
    print(x//(k-1) + (n-x-1)//(k-1))
elif (x%(k-1)==0 and (n-x-1)%(k-1)!=0) or (x%(k-1)!=0 and (n-x-1)%(n-k)==0):
    print(x//(k-1)+(n-x-1)//(k-1)+1)
else:
    print(x//(k-1)+(n-x-1)//(k-1)+2)

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:
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))

point = a.index(1)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N,K=map(int, input().split())
A = list(map(int, input().split()))

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

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
import heapq as hq
gcd = math.gcd
n,k = ma()
A = list(ma())
mi = min(A)
cnt = 0
ans = 0
for a in A:
    if a==mi:
        if cnt==0:
            continue
    cnt+=1
    if cnt ==k-1:
        ans+=1
        cnt=0
if cnt>0:ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
import heapq as hq
gcd = math.gcd
n,k = ma()
A = list(ma())
mi = min(A)
cnt = 0
ans = 0
for a in A:
    if a==mi:
        if cnt==0:
            continue
    cnt+=1
    if cnt ==k:
        ans+=1
        cnt=0
if cnt>0:ans+=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()))

X=A.index(1)

P=ceil(X/(K-1))
Q=ceil((N-X-1)/(K-1))
print(P+Q)

Submission status: Wrong Answer

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

X=A.index(1)

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

Submission status: Wrong Answer

Solution code:
from math import ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
idx = a.index(min(a))
ri, le = idx, len(a) - idx - 1
print(ceil(ri/(k-1))+ ceil(le/(k-1)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n,k=MI()
	A=LI()

	a=A.index(1)

	b=n-a-1
	k-=1


	print((-(-a//k)-(-b//k)))




if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import math

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

A = sorted(A)
minA = min(A)


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




for i in range(N):
    if A[i] != minA:
        start = i
        length = (N-start)
        if length % (K-1) != 0:
            print((math.ceil(length /(K-1))))
            exit()
        else:
            print(int((length / K-1)+1))
            exit()

Submission status: Wrong Answer

Solution code:
import math

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

#提示された配列をソートする
A = sorted(A)

#リスト内の最小値を基準に、リストを塗い変えていく。
minA = min(A)

# NとKが一致する時
if N == K:
  print(1)
  exit()




for i in range(N): #For文でリストAから最小値以外が出てくるまで舐める(最小値が複数個ある時の対策)
    if A[i] != minA:
        start = i #リスト内で一番最後の最小値を見つける

        length = (N-start) # 最小値がいくつあるか確かめる

        print(int((length / K-1)+1))
        exit()

Submission status: Wrong Answer

Solution code:
import math

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

A = sorted(A)
minA = min(A)

A = sorted(A)
minA = min(A)

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




for i in range(N):
    if A[i] != minA:
        start = i
        length = (N-start)
        if length % (K-1) != 0:
            print((math.ceil(length /(K-1))))
            exit()
        else:
            print(int((length / K-1)+1))
            exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    if n == k:
        print(1)
    else:
        ans = ((n + (k - 2)) // (k-1))
        if a[0] == 1 or a[-1] == 1:
            ans -= 1
        print(ans)
        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    if n == k:
        print(1)
    else:
        print((n + (k - 2)) // (k-1))
        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    if n == k:
        print(1)
    else:
        print(n // (k-1))
        

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Wrong Answer

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

a = len(A)
if a == K:
  ans = 1
else:
  ans = math.ceil(a /(K-1))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
a = readInts()
k-=1
i = a.index(1)

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

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]

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

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]

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


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


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


# In[10]:


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


# In[ ]:

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
am = 0
if n <= m:
    print(1)
    exit()
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
    am += i % (m - 1)
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
    am += (n - 1 - i) % (m - 1)
if am == m - 1:
    count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
am = 0
if n <= m - 1:
    print(1)
    exit()
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
    am += i % (m - 1)
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
    am += (n - 1 - i) % (m - 1)
if am == m - 1:
    count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
c = 0
am = 0
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
    am += i % (m - 1)
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
    am += (n - 1 - i) % (m - 1)
if am == m - 1:
    count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
c = 0
am = 0
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
    am += i % (m - 1)
    c += 1
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
    am += (n - 1 - i) % (m - 1)
    c += 1
if am >= m - 1 and c == 2:
    count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
am = 0
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
    am += i % (m - 1)
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
    am += (n - 1 - i) % (m - 1)
if am >= m - 1:
    count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
am = 0
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
    am += i % (m - 1)
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
    am += (n - 1 - i) % (m - 1)
if am >= m:
    count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
i = ar.index(1)
count = 0
if i % (m - 1) == 0:
    count += i // (m - 1)
else:
    count += i // (m - 1) + 1
if (n - 1 - i) % (m - 1) == 0:
    count += (n - 1 - i) // (m - 1)
else:
    count += (n - 1 - i) // (m - 1) + 1
print(count)

Submission status: Wrong Answer

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

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

f = 0
if n%2 == 0:
    if cnt >= n//2:
        f = (len(a)-1)-cnt
    else:
        f = cnt
else:
    if cnt >= n//2+1:
        f = (len(a)-1)-cnt
    else:
        f = cnt


if cnt >= k:
    if (n-k)%(k-1) != 0:
        ans = ((n-k)//(k-1))+2
        print(ans)
    else:
        ans = ((n-k)//(k-1))+2
        print(ans)
else:
    if (n-k)%(k-1) != 0:
        ans = ((n-k)//(k-1))+2
        print(ans)
    else:
        ans = ((n-k)//(k-1))
        print(ans)

Submission status: Wrong Answer

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

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

f = 0
if n%2 == 0:
    if cnt >= n//2:
        f = (len(a)-1)-cnt
    else:
        f = cnt
else:
    if cnt >= n//2+1:
        f = (len(a)-1)-cnt
    else:
        f = cnt


if cnt >= k:
    if (n-k)%(k-1) != 0:
        ans = ((n-k)//(k-1))+2
        print(ans)
    else:
        ans = ((n-k)//(k-1))+2
        print(ans)
else:
    if (n-k)%(k-1) != 0:
        ans = ((n-k)//(k-1))+2
        print(ans)
    else:
        ans = ((n-k)//(k-1))+1
        print(ans)

Submission status: Wrong Answer

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

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

f = 0
if n%2 == 0:
    if cnt >= n//2:
        f = (len(a)-1)-cnt
    else:
        f = cnt
else:
    if cnt >= n//2+1:
        f = (len(a)-1)-cnt
    else:
        f = cnt


if cnt >= k:
    if (n-k)%(k-1) != 0:
        ans = ((n-k)//(k-1))+2
        print(ans)
    else:
        ans = ((n-k)//(k-1))+2
        print(ans)
else:
    if (n-k)%(k-1) != 0:
        ans = ((n-k)//(k-1))+1
        print(ans)
    else:
        ans = ((n-k)//(k-1))+1
        print(ans)

Submission status: Wrong Answer

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

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

f = 0
if n%2 == 0:
    if cnt >= n//2:
        f = (len(a)-1)-cnt
    else:
        f = cnt
else:
    if cnt >= n//2+1:
        f = (len(a)-1)-cnt
    else:
        f = cnt


if cnt >= k:
    if (n-k)%(k-1) != 0:
        ans = ((n-k)//(k-1))+2
        print(ans)
    else:
        ans = ((n-k)//(k-1))+1
        print(ans)
else:
    if (n-k)%(k-1) != 0:
        ans = ((n-k)//(k-1))+1
        print(ans)
    else:
        ans = ((n-k)//(k-1))+1
        print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split());a = list(map(int,input().split()));ans = 0
 
for n in range(1,N):
  ans += 1
  a_n = 3 +(n-1)*(K-1)
  if a_n >= N:
    print(ans)
    exit()

Submission status: Wrong Answer

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

a.sort()
ans = 0

for n in range(N):
  ans += 1
  a_n = 3 +(n-1)*(K-1)
  if a_n >= K:
    print(ans)
    exit()

Submission status: Wrong Answer

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

# 最小値付近から攻める
idx = a.index(min(a))
right = n - idx - 1
left = idx

q1,r1 = divmod(left, k-1)
q2,r2 = divmod(right, k-1)
print(q1 + q2 + min(r1,1) + min(r2,1))

Submission status: Wrong Answer

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

# 最小値付近から攻める
idx = a.index(min(a))
right = n - idx - 1
left = idx

q1,r1 = divmod(left, k-1)
q2,r2 = divmod(right, k-1)
print(q1, q2, r1, r2)
print(q1 + q2 + min(r1,1) + min(r2,1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
a = lr()
ind = 0
p = inf
for i,num in enumerate(a):
    if num == 1:
        ind = i
for i in range(k):
    l = ind-i
    r = l+k-1
    ans = 1
    if l > 0:
        ans += (l+k-2)//(k-1)
    if r < n-1:
        ans += (n-r+1+k-2)//(k-1)
    p = min(ans,p)
print(p)

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
a = lr()
ind = 0
p = inf
for i,num in enumerate(a):
    if num == 1:
        ind = i
for i in range(k):
    l = ind-i
    r = l+k-1
    ans = 1
    if l > 0:
        ans += (l+k-2)//(k-1)
    if r < n-1:
        ans += (n-r+1)//(k-1)
    p = min(ans,p)
print(p)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
lis = list(map(int, input().split()))
l = lis.index(1)
Lis = list(reversed(lis))
L = Lis.index(1)
i = 0
j = 0

if l + 1 >= K:
  r = (l + 1 - K) % (K - 1)
  if r != 0:
    r = K - r
else:
  r = K - l - 1
  
if L + 1 >= K:
  R = K - (L + 1 - K) % (K - 1)
  if R != 0:
    R = K - R
else:
  R = K - L - 1

if r >= R:
  if r == K - 1:
    r = 0
    
  while l - i * K + i > 0:
    i += 1

  while l + r + j * K - j < N - 1:
    j += 1
  
else:
  if R == K - 1:
    R = 0
    
  while L - i * K + i > 0:
    i += 1

  while L + R + j * K - j < N - 1:
    j += 1
  
print(max(1, i + j))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
lis = list(map(int, input().split()))
l = lis.index(1)
Lis = list(reversed(lis))
L = Lis.index(1)
i = 0
j = 0

if l + 1 >= K:
  r = (l + 1 - K) % (K - 1)
else:
  r = K - l - 1
  
if L + 1 >= K:
  R = (L + 1 - K) % (K - 1)
else:
  R = K - L - 1

if r >= R:
  if r == K - 1:
    r = 0
    
  while l - i * K + i > 0:
    i += 1

  while l + r + j * K - j < N - 1:
    j += 1
  
else:
  if R == K - 1:
    R = 0
    
  while l - R - i * K + i > 0:
    i += 1

  while l + j * K - j < N - 1:
    j += 1
  
print(max(1, i + j))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
lis = list(map(int, input().split()))
l = lis.index(1)
Lis = list(reversed(lis))
L = Lis.index(1)
i = 0
j = 0

if l + 1 >= K:
  r = (l + 1 - K) % (K - 1)
else:
  r = K - l - 1
  
if L + 1 >= K:
  R = (L + 1 - K) % (K - 1)
else:
  R = K - L - 1

if r >= R:
  while l - i * K + i > 0:
    i += 1

  while l + r + j * K - j < N - 1:
    j += 1
  
else:
  while l - R - i * K + i > 0:
    i += 1

  while l + j * K - j < N - 1:
    j += 1
  
print(max(1, i + j))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
lis = list(map(int, input().split()))
l = lis.index(1)
Lis = list(reversed(lis))
L = Lis.index(1)
i = 0
j = 0

if l + 1 >= K:
  r = (l + 1 - K) % (K - 1)
else:
  r = K - l - 1
  
if L + 1 >= K:
  R = (L + 1 - K) % (K - 1)
else:
  R = K - L - 1

if r >= R:
  while l - i * K + i >= 0:
    i += 1

  while l + r + j * K - j < N - 1:
    j += 1
  
else:
  while l - R - i * K + i >= 0:
    i += 1

  while l + j * K - j < N - 1:
    j += 1
  
print(i + j)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
lis = list(map(int, input().split()))
l = lis.index(1)
i = 0
j = 0
r = (l + 1) % K
R = (N - 1 - l) % K

if r >= R:
  while l - i * K + i > 0:
    i += 1

  while l + r + j * K - j < N - 1:
    j += 1
  
else:
  while l - R - i * K + i > 0:
    i += 1

  while l + j * K - j < N - 1:
    j += 1
  
print(i + j)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
lis = list(map(int, input().split()))
l = lis.index(1)
i = 0
j = 0
r = (l + 1) % K
R = (N - l) % K

if r >= R:
  while l - i * K + i > 0:
    i += 1

  while l + r + j * K - j < N - 1:
    j += 1
  
  print(i + j)
  
else:
  while l - R - i * K + i > 0:
    i += 1

  while l + j * K - j < N - 1:
    j += 1
  
  print(i + j)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
lis = list(map(int, input().split()))
l = lis.index(1)
i = 0
j = 0
r = (l + 1) % K

while l - i * K + i > 0:
  i += 1

while l + r + j * K - j < N - 1:
  j += 1
  
print(i + j)