/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 348.0 KiB
#2 Accepted 6ms 532.0 KiB
#3 Accepted 7ms 580.0 KiB
#4 Accepted 5ms 380.0 KiB
#5 Accepted 5ms 532.0 KiB
#6 Accepted 5ms 700.0 KiB
#7 Accepted 2ms 536.0 KiB
#8 Accepted 2ms 696.0 KiB
#9 Accepted 5ms 1.277 MiB
#10 Accepted 6ms 1.367 MiB
#11 Accepted 2ms 788.0 KiB
#12 Accepted 2ms 792.0 KiB
#13 Accepted 5ms 1.777 MiB
#14 Accepted 2ms 836.0 KiB

Code

#include <bits/stdc++.h>
#define int long long 
#define ll long long
#define ull unsigned long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define max_ele(v) *max_element(v.begin(), v.end())
#define min_ele(v) *min_element(v.begin(), v.end())
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v) reverse(v.begin(), v.end())
#define REV_SORT(v) sort((v).begin(), (v).end(), greater<>())
#define all(v) v.begin(), v.end()
#define vint vector<int>
#define u_set unordered_set
#define u_map unordered_map
#define setbit(x) __builtin_popcount(x)
#define lead_zero(x) __builtin_clz(x) 
#define trail_zero(x) __builtin_ctz(x) 
#define coutall(v) for(auto &&it : v) cout << it <<" "
#define coutnl(v) for(auto &&it : v) cout << it <<'\n'
#define cinall(v) for(auto &&it : v) cin >> it
#define cin2d(v) for(auto &&row : v) for(auto &&element : row) cin >> element;
#define cout2d(v) for (const auto& row : v) { for (const auto& element : row) cout << element << ' '; cout << '\n';}
#define nl cout << '\n';
#define endl '\n';
using namespace std;
#define m1(x) template<class T, class... U> void x(T&& a, U&&... b) 
#define m2(x) (int[]){(x forward<U>(b),0)...}
m1(print) { cout << forward<T>(a);  m2(cout << " " <<); cout << "\n"; } 
m1(read) { cin >> forward<T>(a); m2(cin >>); }
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

void debug_mode(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}

void solve();
int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    //debug_mode();
    int TestCase = 1;
    cin >> TestCase; 
    int case_no = 1;
    while (TestCase--){
        // cout << "Case " << case_no++ << ": ";
        solve();
        // cout << '\n';
    }
    return 0;
}

void solve(){
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int res = 0;
    priority_queue<int> pq;
    for(int i = 0; i < n; ){
        if(s[i] == '0'){i++; continue;}
        int cnt = 0;
        int pos = i;
        while(pos < n and s[pos] == '1'){
            cnt++;
            pos++;
        }
        pq.push(cnt);
        i = pos;
    }
    while(!pq.empty() and k >= 0){
        res += pq.top();
        pq.pop();k--;
    }
    print(res);
}

Information

Submit By
Type
Submission
Problem
P1159 Binary String
Contest
Brain Booster #8
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 14:50:25
Judged At
2025-02-17 14:50:25
Judged By
Score
100
Total Time
7ms
Peak Memory
1.777 MiB