Problem:


Score : 300 points

Problem Statement

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

On this sequence, Snuke can perform the following operation:

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

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

Constraints

2 \leq K \leq N \leq 100000

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

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

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

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

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4



Sample input:
4 3
2 3 1 4


Sample output:
2

Submission status: Wrong Answer

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

m = min(A)
i = A.index(m)
k -= 1
cnt = 0
left = i
right = n-1-i
cnt += -(-left//k)
cnt += -(-right//k)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math

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

if N == K:
    print(1)
    sys.exit()
for i in range(N):
    if A[i] == 1:
        print(math.ceil(i/(K-1)) + math.ceil((N-i-1)/(K-1)))
        break

Submission status: Wrong Answer

Solution code:
import sys
import math

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

if N == K:
    print(1)
    sys.exit()
for i in range(N):
    if A[i] == 1:
        print(math.floor((i+1)/(K-1)) + math.ceil((N-i-1)/(K-1)))
        break

Submission status: Wrong Answer

Solution code:
import sys
import math

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

for i in range(N):
    if A[i] == 1:
        print(math.ceil(i/(K-1)) + math.ceil((N-i-1)/(K-1)))
        break

Submission status: Wrong Answer

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

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

ans = 0
# Left
if (N-(idx+K)) % (K-1) == 0:
  ans += (N-(idx+K))//(K-1)+1
else:
  ans += (N-(idx+K))//(K-1)+1+1

# Right
if (idx-(K-1)) % (K-1) == 0:
  ans += (idx-(K-1))//(K-1)+1
else:
  ans += (idx-(K-1))//(K-1)+1+1
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
# Left
if (N-idx-K) % (K-1) == 0:
  ans += (N-idx-K)//(K-1)+1
else:
  ans += (N-idx-K)//(K-1)+1+1
# Right
if ((idx+1)-K) % (K-1) == 0:
  ans += ((idx+1)-K)//(K-1)+1
else:
  ans += ((idx+1)-K)//(K-1)+1+1
print(ans)

Submission status: Wrong Answer

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

m = min(A)
i = A.index(m)
cnt = 0
if i!=0:
    cnt += -(-(i-1)//(k-1))
if i!=n-1:
    cnt += -(-n+i)//(k-1)

print(cnt)

Submission status: Wrong Answer

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

m = min(A)
i = A.index(m)
cnt = 0
cnt += -(-(i-1)//(k-1))
cnt += -(-n+i)//(k-1)

print(cnt)

Submission status: Wrong Answer

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

index = a.index(1)
left = a[:index]
right = a[index+1:]

import math
num_left = math.ceil( len(left)/(k-1) )
num_right = math.ceil( len(right)/(k-1) )
print(num_left+num_right)

Submission status: Wrong Answer

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


print((n+k-2)//(k-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:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
if N == K:
    print(1)
elif N == (K-1)*2 + 1:
    print(2)
elif K == 2:
    print(N-1)
else:
    ans = ceil(N/(K-1))
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = A.index(1)
R = N - L - 1
if N == K:
    print(1)
elif L <= K-1  or R <= K-1:
    print(ceil((N-1)/(K-1)))
else:
    ansL = ceil(L/(K-1))
    ansR = ceil((R-max(L%(K-1)-1,0))/(K-1))
    print(ansL + ansR)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = A.index(1)
R = N - L - 1
if N == K:
    print(1)
elif L <= K-1  or R <= K-1:
    print(ceil((N-1)/(K-1)))
else:
    ansL = ceil(L/(K-1))
    ansR = ceil((R-L%(K-1)-1)/(K-1))
    print(ansL + ansR)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = A.index(1)
R = N - L - 1
if N == K:
    print(1)
elif L <= K-1  or R <= K-1:
    print(ceil((N-1)/(K-1)))
else:
    ansL = ceil(L/(K-1))
    ansR = ceil(R/(K-1))
    print(ansL + ansR)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = A.index(1)
R = N - L - 1
if N == K:
    print(1)
elif L <= K  or R <= K:
    print(ceil((N-1)/(K-1)))
else:
    ansL = ceil(L/(K-1))
    ansR = ceil(R/(K-1))
    print(ansL + ansR)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = A.index(1)
R = N - L - 1
if N == K:
    print(1)
elif L == 0 or R == N-1:
    print((N-1)%(K-1))
else:
    ansL = ceil(L/(K-1))
    ansR = ceil((max(L%(K-1)-1,0) + R)/(K-1))
    print(ansL + ansR)

Submission status: Wrong Answer

Solution code:
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
ind = A.index(1)
L = ind
R = N - L - 1
if N == K:
    print(1)
else:
    if L > 0:
        ansL = ceil(L/(K-1))
    else:
        ansL = 0
    if R > 0:
        ansR = ceil((max(L%(K-1)-1,0) + R)/(K-1))
    else:
        ansR = 0
    print(ansL + ansR)

Submission status: Wrong Answer

Solution code:
A = list(map(int, input().split()))
B = input()
if A[0]%2 == 0:
    A[0] += 1
ans = A[0] // (A[1]-1)
if ans == 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()))
ans=0
for i in range(n):
  if a[i]==1:
    ind=i
ans+=math.ceil(ind/(k-1))+math.ceil((n-ind-1)/(k-1))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ind=10**7
ans=0
for i in range(n):
  if a[i]==1:
    ind=i
ans+=math.ceil(ind/(k-1))+math.ceil((n-ind-1)/(k-1))

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
ind=10**7
ans=0
for i in range(n):
  if a[i]==1:
    ind=i
ans+=math.ceil(ind/(k-1))+math.ceil((n-ind)//(k-1))

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = [int(x) for x in input().split()]
print(1 + (n-k)%(k-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
if n<=k:
  print(1)
  exit()
n=n-k
if n%k==0:
  print(1+n//(k-1))
else:
  print(1+n//(k-1)+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k,*_=map(int,open(0).read().split())
print(-~n//-~k)

Submission status: Wrong Answer

Solution code:
n,k,*_=map(int,open(0).read().split())
print(~-n//~-k)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=1000000
for i in range(n):
  if a[i]==1:
    x=i+1

b=x-1
c=n-x
ans=0
if b%(k-1)==0:
  ans+=b//(k-1)
else:
  ans+=b//(k-1)+1
if c%(k-1)==0:
  ans+=c//(k-1)
else:
  ans+=c//(k-1)+1
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=1000000
for i in range(n):
  if a[i]==1:
    x=i+1

b=x-1
c=n-x
ans=0
if b%2==0:
  ans+=b//2
else:
  ans+=b//2+1
if c%2==0:
  ans+=c//2
else:
  ans+=c//2+1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b


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

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

    x = A.index(1)
    ans = 0
    ans += x // (K - 1)
    if x % (K - 1) != 0:
        ans += 1
    ans += ((N - 1) - x) // (K - 1)
    if ((N - 1) - x) % (K - 1) != 0:
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b


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

    x = A.index(1)
    ans = 0
    ans += x // (K - 1)
    if x % (K - 1) != 0:
        ans += 1
    ans += ((N - 1) - x) // (K - 1)
    if ((N - 1) - x) % (K - 1) != 0:
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K= map(int,input().split())
A = list(map(int,input().split()))
mi=np.argmin(A)
mi2=np.argmin(A)
s=0
while True:
  if mi>0:
    mi=mi-K+1
    s=s+1
    #print(s,mi)
  else:
    break
while True:
  if mi2<N-1:
    mi2=mi2+K-1
    s=s+1
    #print(s,mi2)
  else:
    break
print(s)

Submission status: Wrong Answer

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

a = A.index(1)

K -= 1

from math import ceil

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 求解処理
x = A.index(1)
y = N - x - 1
ans = math.ceil(x / (K - 1)) + math.ceil(y / (K - 1))

# 結果出力
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 求解処理
x = A.index(1)
y = N - x - 1
ans = math.ceil(x / (K - 1)) + \
    math.ceil((y - ((K - 1) - x % (K - 1))) / (K - 1))

# 結果出力
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力を取得
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 求解処理
x = A.index(1)
y = N - x - 1
ans = math.ceil(x / (K - 1)) + math.ceil((y - (x % (K - 1))) / (K - 1))

# 結果出力
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    p=A.index(1)
    count =0
    count += p//(K-1)
    if p%(K-1) !=0:
        count +=1

    l = N-p-1
    count += l//(K-1)
    if l%(K-1) !=0:
        count +=1

    print(count)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=min(a)
x=[-1]
for i in range(n):
    if a[i]==s:
        x.append(i)
x.append(n)
X=len(x)
ans=0
for i in range(X-1):
    y=(x[i+1]-x[i]-1)//(k-1)
    if (x[i+1]-x[i]-1)%(k-1)!=0:
        y+=1
    ans+=y
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    min_index = a_lst.index(1)

    if n == k:
        answer = 1
    else:
        before = 0
        tmp1 = 0
        while tmp1 < min_index:
            before += 1
            tmp1 = (k - 1) * before

        after = 0
        tmp2 = 0
        while tmp2 < n - 1 - min_index:
            after += 1
            tmp2 = (k - 1) * after

        answer = before + after

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    min_index = a_lst.index(1)

    before = 0
    tmp1 = 0
    while tmp1 < min_index:
        before += 1
        tmp1 = (k - 1) * before

    after = 0
    tmp2 = 0
    while tmp2 < n - 1 - min_index:
        after += 1
        tmp2 = (k - 1) * after

    answer = before + after
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    min_index = a_lst.index(1)

    if min_index - 1 >= 0:
        before = 1 + (min_index - 1) // (k - 1)
    else:
        before = 1

    tmp = n - min_index - 1
    if tmp - 1 >= 0:
        after = 1 + (tmp - 1) // (k - 1)
    else:
        after = 1

    answer = before + after
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    min_index = a_lst.index(1)

    if min_index - 1 >= 0:
        before = 1 + (min_index - 1) // 2
    else:
        before = 1

    tmp = n - min_index - 1
    if tmp - 1 >= 0:
        after = 1 + (tmp - 1) // 2
    else:
        after = 1

    answer = before + after
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    min_index = a_lst.index(1)
    before = 1 + (min_index - 1) // 2
    tmp = n - min_index - 1
    after = 1 + (tmp - 1) // 2
    answer = before + after
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if N <= K:
  cnt = 1
else:
  i = A.index(1)
  left = i
  right = N - i - 1

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

print(cnt)

Submission status: Wrong Answer

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

i = A.index(1)
left = i
right = N - i - 1

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

print(cnt)

Submission status: Wrong Answer

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

i = A.index(1)
left = len(A[:i])
right = len(A[i+1:])

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

print(cnt)

Submission status: Wrong Answer

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

if n == k:
    print(1)
    exit()
for i in range(10000):
    if i * (k - 1) + k < n and n == (i + 1) * (k - 1) + k:
        print(i+1)
    elif i * (k - 1) + k < n and n < (i + 1) * (k - 1) + k:
        print(i+2)

Submission status: Wrong Answer

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

if n == k:
    print(1)
    exit()
for i in range(10000):
    # print(i * (k - 1) + k)
    # print((i + 1) * (k - 1) + k)
    if i * (k - 1) + k < n and n <= (i + 1) * (k - 1) + k:
        print(i+2)

Submission status: Wrong Answer

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

if n == k:
    print(1)
    exit()
for i in range(10):
    # print(i * (k - 1) + k)
    # print((i + 1) * (k - 1) + k)
    if i * (k - 1) + k < n and n <= (i + 1) * (k - 1) + k:
        print(i+2)

Submission status: Wrong Answer

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

ans = 0
# 1よりも左に数列があるなら左を計算
if index != 1:
    if index < K:
        ans += 1
        index = K
    else:
        p = index
        while p > 1:
            p -= (K-1)
            ans += 1
# 1よりも右に数列があるなら右を計算
while index < N:
    index = index + (K - 1)
    ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
# 0よりも左があるなら左を計算
if index != 1:
    p = index - K
    ans += 1
    if p < 0:
        index = K
    p += 1
    while p > 0:
        p = p - K
        ans += 1
# 0よりも右があるなら右を計算
while index < N:
    index = index + (K - 1)
    ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
# 0よりも左があるなら左を計算
if index != 0:
    p = index - K
    ans += 1
    if p < 0:
        index = K
    p += 1
    while p > 0:
        p = p - K
        ans += 1
# 0よりも右があるなら右を計算
while index < N:
    index = index + (K - 1)
    ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
if index != 0:
    p = (index + 1) - K
    ans += 1
    if p < 0:
        index = K - 1

    while p > 0:
        p = p - K
        ans += 1

while index < (N - 1):
    index = index + K - 1
    ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
if index != 0:
    p = index - K + 1
    ans += 1
    if p < 0:
        index = index + (-1 * p)
    elif p > 0:
        while p > 0:
            p = p - K + 1
            ans += 1
if index < (N - 1):
    ans += 1
    index = index + K - 1
    while index < (N - 1):
        index = index + K - 1
        ans += 1

print(ans)

Submission status: Wrong Answer

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


def get_1_index(a):
    for i,j in enumerate(a):
        if j==1:
            return i


index=get_1_index(a)

mae=index
usiro=n-index-1

print(math.ceil(mae/(k-1))+math.ceil(usiro/(k-1)))

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if K == 2:
        print(N)
    else:
        ans = 10**10
        for k in range(K):
            v = 0
            if k > 0:
                v += 1
            v += (N - k) // (K - 1)
            if (N - k) % (K - 1) > 1:
                v += 1
            if v < ans:
                ans = v
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ans = 10**10
    for k in range(K):
        v = 0
        if k > 0:
            v += 1
        v += (N - k) // (K - 1)
        if (N - k) % (K - 1) > 1:
            v += 1
        if v < ans:
            ans = v
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ans = 10**10
    for k in range(K):
        v = 0
        if k > 0:
            v += 1
        v += (N - k) // (K - 1)
        if (N - k) % K > 1:
            v += 1
        if v < ans:
            ans = v
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = min(a)
ans = 0
indl = [-1,n]
for i in range(n):
  if a[i]==p:
    indl.append(i)
indl.sort(reverse=True)
for i in range(len(indl)-1):
  ans += (indl[i]-indl[i+1]-1)//(k-1)+((indl[i+1]-indl[i]-1)%(k-1)!=0)
print(ans)

Submission status: Wrong Answer

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

for i_1 in range(n):
    if a[i_1]==1:
        break

#print(i_1)
#print(a[:i_1],a[i_1+1:])
mae = len(a[:i_1])//(k-1)
mae_amari = len(a[:i_1])%(k-1)
ushiro = len(a[i_1+1:])//(k-1)
ushiro_amari = len(a[i_1+1:])%(k-1)
#print(mae,mae_amari)
#print(ushiro,ushiro_amari)
if mae+mae_amari==0:
    print(ushiro+ushiro_amari)
elif ushiro+ushiro_amari==0:
    print(mae+mae_amari)
else:
    if mae_amari+1+ushiro_amari<=k:
        print(mae+ushiro+1)
    else:
        print(mae+ushiro+2)

Submission status: Wrong Answer

Solution code:
#基本全部1にする
def main():
    import math
    n,k = list(map(int, input().split()))
    As = list(map(int,input().split()))
    pos = As.index(1)
    #print(pos)

    if pos/(k-1) >=1:
        pos_f = math.ceil(pos/(k-1))
    else:
        res = math.ceil((n-k)/(k-1))
        return res +1
    if pos + k <=n:
        pos_b = math.ceil((n-1-pos)/(k-1))
    else:
        res = math.ceil((n-k)/(k-1))
        return res +1
    return pos_f + pos_b

    
print(main())

Submission status: Wrong Answer

Solution code:
#基本全部1にする
import math
n,k = list(map(int, input().split()))
As = list(map(int,input().split()))
pos = As.index(1)
#print(pos)
pos_b = math.ceil((n-1-pos)/(k-1))
pos_f = math.ceil(pos/(k-1))
print(pos_b+pos_f)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
an = list(map(int,input().split()))

min_an_index = np.argmin(an)

count = 0
a = min_an_index
b = N - min_an_index - 1

if K-1 > a:
    b -= K - 1 - a
    if b < 0:
        b = 0
        count += 1
if K-1 > b:
    a -= K - 1 - b
    if a < 0:
        a = 0
        count += 1
if a > 0:        
    a1 = a // (K-1)
    if a % (K-1) != 0:
        a1 += 1
if a <= 0:
    a1 = 0
    
if b > 0:    
    b1 = b // (K-1)
    if b % (K-1) != 0:
        b1 += 1
if b <= 0:
    b1 = 0

count += a1 + b1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
an = list(map(int,input().split()))

min_an_index = np.argmin(an)

count = 0
a = min_an_index
b = N - min_an_index - 1

if K-1 > a:
    b -= K - 1 - a
    if b < 0:
        b = 0
        count += 1
if K-1 > b:
    a -= K - 1 - b
    if a < 0:
        a = 0
        count += 1
        
a1 = a // (K-1)
if a % (K-1) != 0:
    a1 += 1
    
b1 = b // (K-1)
if b % (K-1) != 0:
    b1 += 1

count += a1 + b1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
an = list(map(int,input().split()))

min_an_index = np.argmin(an)

a = min_an_index
b = N - min_an_index - 1

if K >= a:
    b -= K - a - 1
    if b < 0:
        b = 1
if K >= b:
    a -= K - b - 1
    if a < 0:
        a = 1
        
a1 = a // (K-1)
if a % (K-1) != 0:
    a1 += 1
    
b1 = b // (K-1)
if b % (K-1) != 0:
    b1 += 1

count = a1 + b1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
an = list(map(int,input().split()))

min_an_index = np.argmin(an)

a = min_an_index
b = N - min_an_index - 1

if K > a:
    b -= K - a - 1
    if b < 0:
        b = 1
if K > b:
    a -= K - b - 1
    if a < 0:
        a = 1
        
a1 = a // (K-1)
if a % (K-1) != 0:
    a1 += 1
    
b1 = b // (K-1)
if b % (K-1) != 0:
    b1 += 1

count = a1 + b1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
an = list(map(int,input().split()))

min_an_index = np.argmin(an)

a = min_an_index
b = N - min_an_index - 1

if K > a:
    b -= K - a - 1
if K > b:
    a -= K - b - 1
    
a1 = a // (K-1)
if a % (K-1) != 0:
    a1 += 1
    
b1 = b // (K-1)
if b % (K-1) != 0:
    b1 += 1

count = a1 + b1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
an = list(map(int,input().split()))

min_an_index = np.argmin(an)

a = min_an_index
b = N - min_an_index - 1

if K < a:
    b -= K - a
if K < b:
    a -= K - b
    
a1 = a // (K-1)
if a % (K-1) != 0:
    a1 += 1
    
b1 = b // (K-1)
if b % (K-1) != 0:
    b1 += 1

count = a1 + b1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
an = list(map(int,input().split()))

min_an_index = np.argmin(an)

a = min_an_index
b = N - min_an_index - 1

if K < a:
    b -= K - b
if K < b:
    a -= K - a
    
a1 = a // (K-1)
if a % (K-1) != 0:
    a1 += 1
    
b1 = b // (K-1)
if b % (K-1) != 0:
    b1 += 1

count = a1 + b1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
an = list(map(int,input().split()))

min_an_index = np.argmin(an)

a = min_an_index
b = N - min_an_index - 1

a1 = a // (K-1)
if a % (K-1) != 0:
    a1 += 1
    
b1 = b // (K-1)
if b % (K-1) != 0:
    b1 += 1

count = a1 + b1
print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:


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

#A.sort()
arr = []
for i in range(1,K):
    if N % i == 0:
        arr.append(i)
#print(arr)

tmp = max(arr)
#print(tmp)
if N==K:
    tmp = N
print(N//tmp)