Submission #62797169


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
char a[500005];
int main(){	
    int n;
    cin>>n;
    cin>>a;
    bool flag=0;
    int cnt=0;
    int lcnt=0,rcnt=0;
    long long ans=LONG_LONG_MAX;
    long long num=0;
    int k=0;
    for(int i=0;i<n;i++){
    	if(a[i]=='1'&&!flag)flag=1,k=i,rcnt++;
    	else if(flag&&a[i]=='0')cnt++;
		else if(flag&&a[i]=='1')num+=cnt,rcnt++; 
    }
    for(int i=k;i<n;i++){
    	if(a[i]=='1'){
    		if(num<ans)ans=num;
    		rcnt--;
    		lcnt++;
		}
		else{
			num-=rcnt;
			num+=lcnt;
		}
	}
	cout<<ans;
	return 0;
}

Submission Info

Submission Time
Task D - Swap to Gather
User huangpintao
Language C++ 20 (gcc 12.2)
Score 425
Code Size 589 Byte
Status AC
Exec Time 10 ms
Memory 4136 KiB

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 1 ms 3452 KiB
00_sample_01.txt AC 1 ms 3648 KiB
00_sample_02.txt AC 1 ms 3464 KiB
01_random_00.txt AC 2 ms 3564 KiB
01_random_01.txt AC 9 ms 4012 KiB
01_random_02.txt AC 7 ms 3824 KiB
01_random_03.txt AC 6 ms 4044 KiB
01_random_04.txt AC 7 ms 3980 KiB
01_random_05.txt AC 8 ms 3972 KiB
01_random_06.txt AC 9 ms 3860 KiB
01_random_07.txt AC 9 ms 3944 KiB
01_random_08.txt AC 10 ms 3936 KiB
01_random_09.txt AC 9 ms 3960 KiB
01_random_10.txt AC 9 ms 3992 KiB
01_random_11.txt AC 8 ms 3992 KiB
01_random_12.txt AC 7 ms 3956 KiB
01_random_13.txt AC 6 ms 3924 KiB
02_random2_00.txt AC 6 ms 3980 KiB
02_random2_01.txt AC 7 ms 3928 KiB
02_random2_02.txt AC 6 ms 3860 KiB
02_random2_03.txt AC 6 ms 3992 KiB
02_random2_04.txt AC 6 ms 4136 KiB
02_random2_05.txt AC 6 ms 3852 KiB
03_handmade_00.txt AC 1 ms 3488 KiB
03_handmade_01.txt AC 1 ms 3444 KiB
03_handmade_02.txt AC 1 ms 3432 KiB
03_handmade_03.txt AC 1 ms 3492 KiB
03_handmade_04.txt AC 6 ms 3836 KiB