Submission #62987634


Source Code Expand

// LUOGU_RID: 204166611
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(x) (x).begin(), (x).end()
vector<ll> a, b;

void f() {
  ll n; string s; cin >> n >> s;
  a.assign(n, 0);
  b.assign(n, 0);
  for(ll i=0, curr=0; i<n; i++){
    if(i) a[i]=a[i-1];
    if(s[i]=='0') a[i]+=curr;
    else curr++;
  }
  for(ll i=n-1, curr=0; i>=0; i--){
    if(i!=n-1) b[i]=b[i+1];
    if(s[i]=='0') b[i]+=curr;
    else curr++;
  }
  ll ans=n*n*n;
  for(ll i=0; i<n-1; i++){
    ans=min(ans, a[i]+b[i+1]);
  }
  cout << ans << endl;
}

int main() {
  int tc=1; 
  // cin >> tc;
  while (tc--){
    // cout << '#' << tc << endl;
    f();
    cout << endl;
  }
}

Submission Info

Submission Time
Task D - Swap to Gather
User veehj
Language C++ 20 (gcc 12.2)
Score 425
Code Size 784 Byte
Status AC
Exec Time 16 ms
Memory 11736 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 2 ms 3488 KiB
00_sample_01.txt AC 1 ms 3424 KiB
00_sample_02.txt AC 1 ms 3528 KiB
01_random_00.txt AC 3 ms 4532 KiB
01_random_01.txt AC 14 ms 11064 KiB
01_random_02.txt AC 12 ms 8740 KiB
01_random_03.txt AC 14 ms 11564 KiB
01_random_04.txt AC 14 ms 11568 KiB
01_random_05.txt AC 14 ms 11488 KiB
01_random_06.txt AC 14 ms 11516 KiB
01_random_07.txt AC 15 ms 11736 KiB
01_random_08.txt AC 16 ms 11512 KiB
01_random_09.txt AC 15 ms 11640 KiB
01_random_10.txt AC 14 ms 11568 KiB
01_random_11.txt AC 13 ms 11568 KiB
01_random_12.txt AC 13 ms 11616 KiB
01_random_13.txt AC 12 ms 11736 KiB
02_random2_00.txt AC 14 ms 11576 KiB
02_random2_01.txt AC 12 ms 11512 KiB
02_random2_02.txt AC 14 ms 11564 KiB
02_random2_03.txt AC 14 ms 11632 KiB
02_random2_04.txt AC 14 ms 11488 KiB
02_random2_05.txt AC 13 ms 11564 KiB
03_handmade_00.txt AC 1 ms 3480 KiB
03_handmade_01.txt AC 1 ms 3500 KiB
03_handmade_02.txt AC 1 ms 3492 KiB
03_handmade_03.txt AC 1 ms 3632 KiB
03_handmade_04.txt AC 13 ms 11636 KiB