結果

問題 No.1437 01 Sort
ユーザー jelljell
提出日時 2021-04-03 01:46:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 584 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 8,516 KB
最終ジャッジ日時 2023-08-25 16:33:00
合計ジャッジ時間 4,143 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,780 KB
testcase_01 AC 15 ms
7,732 KB
testcase_02 AC 15 ms
7,732 KB
testcase_03 AC 15 ms
8,108 KB
testcase_04 AC 14 ms
7,888 KB
testcase_05 AC 15 ms
7,800 KB
testcase_06 AC 15 ms
8,136 KB
testcase_07 AC 15 ms
7,844 KB
testcase_08 AC 15 ms
7,796 KB
testcase_09 AC 15 ms
7,796 KB
testcase_10 AC 16 ms
7,760 KB
testcase_11 AC 15 ms
7,896 KB
testcase_12 WA -
testcase_13 AC 128 ms
8,408 KB
testcase_14 AC 123 ms
8,312 KB
testcase_15 AC 173 ms
8,312 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()
zeros = s.count('0')

if not zeros or zeros == n:
    print(0)
    exit()

ans = n * n
l = [0, 0]

if s[0] != '0':
    for c in s[1:]:
        if c != '0':
            break
        l[1] += 1
else:
    l[0] += 1
    for c in s[1:]:
        if c != '0':
            break
        l[0] += 1

for i, c in enumerate(reversed(s)):
    ans = min(ans, i + n * (zeros - l[0]))
    if c != '0':
        l[1] = l[0]
        if l[0]:
            l[0] = 1
    else:
        l[0] += 1
        l[1] += 1
        ans = min(ans, i + n * max(1, zeros - l[1]))

print(ans)
0