/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Runtime Error 1ms 568.0 KiB
#3 Runtime Error 1ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define int int64_t
#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define acc accumulate
#define f first 
#define s second 
#define mx(v) v[max_element(v.begin(), v.end()) - v.begin()] 
#define mn(v) v[min_element(v.begin(), v.end()) - v.begin()] 
#define inp(v, n) for (int i = 0; i < n; i++) { cin >> v[i]; } 

//---- Debugger ---- //
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
ll binpow(ll b,ll p,ll mod){ll ans=1;b%=mod;for(;p;p>>=1){if(p&1)ans=ans*b%mod;b=b*b%mod;}return ans;}
//----------------- //


const int MOD = 1e9 + 7 ; 
 
void solve()
{
    int n , k ;
    cin >> n >> k ;
    string s ;
    cin >> s ;
    vi v ;
    int c = 0 ;
    for (int i = 0 ; i < s.size() ; i++) {
        if (s[i] == '1') {
            c++ ;
        }
        else {
            if (c > 0) {
                v.pb(c) ;
                c = 0 ;
            }
        }
    }
    if (c > 0) {
        v.pb(c) ;
    }
    sort(rall(v)) ;
    int ans = 0 ;
    int s1 = s.size() ;
    for (int i = 0 ; i < min(s1,k+1) ; i++) {
        ans+=(v[i]) ;
    }
    
    cout << ans ;
}

int32_t main()
{
    fast;
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
        cout << "\n";
    }
}

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 15:23:46
Judged At
2025-02-17 15:23:46
Judged By
Score
0
Total Time
1ms
Peak Memory
568.0 KiB