結果

問題 No.1437 01 Sort
ユーザー tyawanmusityawanmusi
提出日時 2021-02-19 18:46:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 945 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 11,848 KB
実行使用メモリ 22,144 KB
最終ジャッジ日時 2023-10-19 04:54:36
合計ジャッジ時間 4,249 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,172 KB
testcase_01 AC 31 ms
10,172 KB
testcase_02 AC 32 ms
10,172 KB
testcase_03 AC 32 ms
10,172 KB
testcase_04 AC 30 ms
10,172 KB
testcase_05 AC 30 ms
10,172 KB
testcase_06 AC 30 ms
10,172 KB
testcase_07 AC 32 ms
10,172 KB
testcase_08 AC 31 ms
10,172 KB
testcase_09 AC 31 ms
10,172 KB
testcase_10 AC 34 ms
10,172 KB
testcase_11 AC 32 ms
10,172 KB
testcase_12 WA -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
s=input()
ans=10**10
zero=s.count("0")
one=n-zero
if zero==0 or zero==n:
  exit(print(0))
se=set()
if s[0]=="1":
  se.add(0)
  for i in range(n-1,-1,-1):
    if s[i]=="1":
      se.add(i)
    else:break
for l in range(n):
  a=list(range(l+n,l+one+n))
  sp_l=(l+one)%n
  sp_r=n
  if sp_l==0:sp_l=n
  #print(sp_l,sp_r)
  for ll in range(n*3):
    b=[]
    for i in range(ll,ll+n):
      if s[i%n]=="1":b.append(i)
    ansl=0
    ansr=0
    flag=True
    if b[0]<=a[0]:
      if sp_l<=((b[0]-1)%n+1)<=sp_r and (b[0]%n not in se):
        ansl=a[0]-b[0]-1
      else:
        ansl=a[0]-b[0]
    for i in range(one):
      if b[i]>a[i]:
        ansr+=1
        if sp_l<=((b[i]-1)%n+1)<=sp_r:
          flag=False
    if ansr:ansr+=flag
    #print(l,ll,"---",max(ansl,ansr)*n+(-l-one)%n,sp_l<=((b[0]-1)%n+1)<=sp_r and (b[0]%n not in se),flag)
    #print(ansl,ansr)
    #print(b,a)
    ans=min(ans,max(ansl,ansr)*n+(-l-one)%n)
print(ans)
0