Submission #62799600


Source Code Expand

Copy
#include<iostream>
using namespace std;
#define int long long
int pre[500010],suf[500010];
int a[500010];
signed main(){
int n;
cin>>n;
int ans=1e15,cnt=0,cnt2=0;
for(int i=0;i<n;i++){
char c;
cin>>c;
a[i]=c-'0';
cnt2+=a[i];
}
pre[0]=suf[n]=0;
for(int i=0;i<n;i++){
if(a[i]==1)pre[i+1]=pre[i],cnt++;
else pre[i+1]=pre[i]+cnt;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<iostream>
using namespace std;
#define int long long

int pre[500010],suf[500010];
int a[500010];

signed main(){
	int n;
	cin>>n;
	int ans=1e15,cnt=0,cnt2=0;
	for(int i=0;i<n;i++){
		char c;
		cin>>c;
		a[i]=c-'0';
		cnt2+=a[i];
	}
	pre[0]=suf[n]=0;
	for(int i=0;i<n;i++){
		if(a[i]==1)pre[i+1]=pre[i],cnt++;
		else pre[i+1]=pre[i]+cnt;
	}
	cnt=0;
	for(int i=n-1;i+1;i--){
		if(a[i]==1)suf[i]=suf[i+1],cnt++;
		else suf[i]=suf[i+1]+cnt;
	}
	for(int i=0;i<=n;i++){
		// cout<<pre[i]<<" "<<suf[i]<<endl;
	}
	for(int i=0;i<n;i++){
		// cout<<i<<" "<<pre[i+1]<<" "<<suf[i+1]<<endl;
		ans=min(ans,pre[i+1]+suf[i+1]);
	}
	cout<<ans;
}
// 011001001
// 111010000

Submission Info

Submission Time
Task D - Swap to Gather
User n_ni
Language C++ 20 (gcc 12.2)
Score 425
Code Size 701 Byte
Status AC
Exec Time 25 ms
Memory 15372 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 1 ms 3516 KB
00_sample_01.txt AC 1 ms 3456 KB
00_sample_02.txt AC 1 ms 3464 KB
01_random_00.txt AC 4 ms 5172 KB
01_random_01.txt AC 24 ms 14368 KB
01_random_02.txt AC 18 ms 11232 KB
01_random_03.txt AC 23 ms 15208 KB
01_random_04.txt AC 23 ms 15172 KB
01_random_05.txt AC 24 ms 15176 KB
01_random_06.txt AC 24 ms 15368 KB
01_random_07.txt AC 25 ms 15152 KB
01_random_08.txt AC 25 ms 15216 KB
01_random_09.txt AC 25 ms 15148 KB
01_random_10.txt AC 25 ms 15088 KB
01_random_11.txt AC 23 ms 15372 KB
01_random_12.txt AC 23 ms 15288 KB
01_random_13.txt AC 23 ms 15364 KB
02_random2_00.txt AC 23 ms 15168 KB
02_random2_01.txt AC 23 ms 15208 KB
02_random2_02.txt AC 22 ms 15172 KB
02_random2_03.txt AC 22 ms 15176 KB
02_random2_04.txt AC 23 ms 15208 KB
02_random2_05.txt AC 22 ms 15216 KB
03_handmade_00.txt AC 1 ms 3456 KB
03_handmade_01.txt AC 1 ms 3508 KB
03_handmade_02.txt AC 1 ms 3580 KB
03_handmade_03.txt AC 1 ms 3596 KB
03_handmade_04.txt AC 22 ms 15176 KB


2025-03-29 (Sat)
00:52:03 +00:00