結果

問題 No.1437 01 Sort
ユーザー tyawanmusityawanmusi
提出日時 2021-02-20 00:26:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,104 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 12,108 KB
実行使用メモリ 30,700 KB
最終ジャッジ日時 2023-10-19 04:54:48
合計ジャッジ時間 4,274 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,432 KB
testcase_01 AC 29 ms
10,264 KB
testcase_02 AC 30 ms
10,264 KB
testcase_03 AC 30 ms
10,264 KB
testcase_04 AC 31 ms
10,264 KB
testcase_05 AC 29 ms
10,264 KB
testcase_06 AC 31 ms
10,264 KB
testcase_07 AC 31 ms
10,264 KB
testcase_08 AC 31 ms
10,264 KB
testcase_09 AC 30 ms
10,264 KB
testcase_10 AC 31 ms
10,264 KB
testcase_11 AC 30 ms
10,264 KB
testcase_12 AC 31 ms
10,264 KB
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

po=[]
for i in range(n):
  if s[i]=="1":po+=[i,i+n,i+n+n,i+n+n+n]
po.sort()

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

  for ll in range(one*3):
    ansl=0
    ansr=0
    flag=True
    flagg=False
    if po[ll]<=a[0]:
      if sp_l<=((po[ll]-1)%n+1)<=sp_r and (po[ll]%n not in se):
        ansl=a[0]-po[ll]-1
      else:
        ansl=a[0]-po[ll]
    if a[one-1]<po[ll+one-1]:
      flag=True
      flagg=False
      ng=-1
      ok=one
      while ng+1!=ok:
        mid=(ng+ok)//2
        if a[mid]<po[ll+mid]:ok=mid
        else:ng=mid
      x=a[ok]
      if x%n:x+=n-(x%n)
      if x<=a[one-1]:
        if a[ok]<=po[ll+ok]<=x:
          flagg=True
        x+=n
      if a[ok]<=po[ll+ok]<=x:
        flag=False
      ansr=one-ok
      if ansr:ansr+=flag
      ansr-=flagg
    ans=min(ans,max(ansl,ansr)*n+(-l-one)%n)
  
print(ans)
0