結果

問題 No.1437 01 Sort
ユーザー tyawanmusityawanmusi
提出日時 2021-01-20 23:43:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 707 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 81,532 KB
実行使用メモリ 255,836 KB
最終ジャッジ日時 2023-10-19 04:54:10
合計ジャッジ時間 4,872 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
57,748 KB
testcase_01 AC 38 ms
53,400 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 39 ms
53,400 KB
testcase_05 AC 39 ms
53,400 KB
testcase_06 AC 40 ms
53,400 KB
testcase_07 AC 39 ms
53,400 KB
testcase_08 AC 39 ms
53,400 KB
testcase_09 AC 40 ms
53,400 KB
testcase_10 AC 38 ms
53,400 KB
testcase_11 AC 41 ms
53,400 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 #

# 計算量 O(N^3)

n = int(input())
s = input()
co = s.count("1")
ans = 10**15

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

for l in range(n):
  x = list(range(l, l+co))
  anss = (n-(l+co)) % n
  sp_l = (l+co) % n
  sp_r = (0 if sp_l == 0 else n)
  for ll in range(co):
    y = a[ll:ll+co]
    flag = 0
    le = 0
    ri = 0
    for i in range(co):
      if y[i] <= x[i]:
        if sp_l <= y[i] % n < sp_r:
          le = max(le, x[i]-y[i]-1)
        else:
          le = max(le, x[i]-y[i])
      else:
        if sp_l <= y[i] % n < sp_r:
          flag = 1
        if ri == 0:
          ri += 1
        ri += 1
    ri -= flag
    ans = min(ans, anss+max(le, ri)*n)
print(ans)
0