Submission #62808075


Source Code Expand

Copy
N = int(input())
S = input()
def solve():
array = []
A_start = 0
for i in range(len(S)):
if S[i] == '1':
array.append(i)
#print("array={}".format(array))
center_index = len(array)//2
center = array[len(array)//2]
result = 0
for i in range(len(array)):
a_i = array[i]
result += abs(center-a_i)-abs(center_index-i)
print(result)
solve()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
N = int(input())
S = input()

def solve():
    array = []
    A_start = 0
    for i in range(len(S)):
        if S[i] == '1':
            array.append(i)

    #print("array={}".format(array))
    center_index = len(array)//2
    center = array[len(array)//2]
    result = 0
    for i in range(len(array)):
        a_i = array[i]
        result += abs(center-a_i)-abs(center_index-i)
    print(result)

solve()

Submission Info

Submission Time
Task D - Swap to Gather
User yasubei
Language Python (CPython 3.11.4)
Score 425
Code Size 428 Byte
Status AC
Exec Time 88 ms
Memory 29588 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 28
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 10 ms 8452 KB
00_sample_01.txt AC 10 ms 8452 KB
00_sample_02.txt AC 10 ms 8404 KB
01_random_00.txt AC 17 ms 10364 KB
01_random_01.txt AC 60 ms 19076 KB
01_random_02.txt AC 45 ms 15752 KB
01_random_03.txt AC 29 ms 9952 KB
01_random_04.txt AC 35 ms 11044 KB
01_random_05.txt AC 43 ms 13172 KB
01_random_06.txt AC 50 ms 15832 KB
01_random_07.txt AC 59 ms 17700 KB
01_random_08.txt AC 64 ms 19832 KB
01_random_09.txt AC 70 ms 21760 KB
01_random_10.txt AC 76 ms 23584 KB
01_random_11.txt AC 81 ms 25760 KB
01_random_12.txt AC 88 ms 27552 KB
01_random_13.txt AC 84 ms 29588 KB
02_random2_00.txt AC 50 ms 17188 KB
02_random2_01.txt AC 83 ms 28144 KB
02_random2_02.txt AC 35 ms 11756 KB
02_random2_03.txt AC 32 ms 10108 KB
02_random2_04.txt AC 40 ms 12556 KB
02_random2_05.txt AC 51 ms 18024 KB
03_handmade_00.txt AC 10 ms 8456 KB
03_handmade_01.txt AC 10 ms 8516 KB
03_handmade_02.txt AC 10 ms 8540 KB
03_handmade_03.txt AC 10 ms 8536 KB
03_handmade_04.txt AC 61 ms 19908 KB


2025-04-04 (Fri)
02:58:12 +00:00