/ SeriousOJ /

Record Detail

Compile Error

foo.cc:39:2: error: stray '#' in program
   39 | }#include<bits/stdc++.h>
      |  ^
foo.cc:39:3: error: 'include' does not name a type
   39 | }#include<bits/stdc++.h>
      |   ^~~~~~~
foo.cc:46:5: error: redefinition of 'int main()'
   46 | int main(){
      |     ^~~~
foo.cc:8:5: note: 'int main()' previously defined here
    8 | int main(){
      |     ^~~~

Code

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define f first 
#define s second 
using namespace std;

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--){
        ll n, k;
        string s;
        cin >> n >> k >> s;
        vector<ll> a;
        while (!s.empty()){
          while (!s.empty() && s.back() == '0') s.pop_back();
          int c = 0;
          while (!s.empty() && s.back() == '1') c++, s.pop_back();
          if (c) a.push_back(c);
        }
        if (a.empty()){
          cout << 0 << endl;
          continue;
        }
        sort(a.rbegin(), a.rend());
        ll cur = a[0];
        ll m = a.size();
        for (int i = 1; i <= min(m, k); i++){
          cur += a[i];
        }
        cout << cur << endl;
    }
}#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define f first 
#define s second 
using namespace std;

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--){
        ll n, k;
        string s;
        cin >> n >> k >> s;
        vector<ll> a;
        while (!s.empty()){
          while (!s.empty() && s.back() == '0') s.pop_back();
          int c = 0;
          while (!s.empty() && s.back() == '1') c++, s.pop_back();
          if (c) a.push_back(c);
        }
        if (a.empty()){
          cout << 0 << endl;
          continue;
        }
        sort(a.rbegin(), a.rend());
        ll cur = a[0];
        ll m = a.size();
        for (int i = 1; i < min(m, k); i++){
          cur += a[i];
        }
        cout << cur << endl;
    }
}

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:55:42
Judged At
2025-02-17 14:56:23
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes