Niloy007

CF contest

Aug 14th, 2020
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define MAX 1000006
  3. #define MOD 1e9
  4. #define pb push_back
  5. #define pairs pair<int, int>
  6. #define vi vector<int>
  7. #define vb vector<bool>
  8. #define vii vector<pairs>
  9. #define lb lower_bound
  10. #define ub upper_bound
  11. #define ll long long
  12. #define endl '\n'
  13. using namespace std;
  14. /* ----------------------------------------------------------------------------------- */
  15.  
  16. #define fastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
  17. #define all(x) x.begin(), x.end()
  18. #define scan(a) scanf("%d", &a)
  19. #define scanll(a) scanf("%lld", &a)
  20. #define scanD(a) scanf("%lf", &a)
  21. #define print(a) printf("%d\n", a)
  22. #define printll(a) printf("%lld\n", a)
  23. #define printD(a) printf("%lf\n", a)
  24. #define printTwo(a) printf("%.2lf\n", a);
  25. #define read(x) freopen(x, "r", stdin)
  26. #define write(x) freopen(x, "w", stdout)
  27. #define rep(i, a, n) for (int i = a; i < n; i++)
  28. #define REP(i, a, n) for (int i = a; i <= n; i++)
  29. #define inputArray(a,n) rep(i, 0, n) cin >> a[i];
  30. #define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
  31. #define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;
  32.  
  33. /* ----------------------------------------------------------------------------------- */
  34.  
  35. #define Cases  cout << "Case " << ++Case << ": ";
  36. #define __test int tt; int Case=0; cin >> tt; while(tt--)
  37. #define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  38.  
  39. #define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
  40. #define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
  41. #define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}
  42.  
  43. /* ----------------------------------------------------------------------------------- */
  44.  
  45. ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
  46. ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
  47.  
  48. struct debugger {
  49.     typedef string::iterator si;
  50.     static void call(si it, si ed) {}
  51.     template<typename T, typename ... aT>
  52.     static void call(si it, si ed, T a, aT... rest) {
  53.         string b;
  54.         for(; *it!=','; ++it)
  55.             if(*it!=' ')
  56.                 b+=*it;
  57.         cout << b << "=" << a << " ";
  58.         call(++it, ed, rest...);
  59.     }
  60. };
  61.  
  62. #define Niloy
  63.  
  64. /* ----------------------------------------------------------------------------------- */
  65.  
  66.  
  67.  
  68. void solve() {
  69.     string str;
  70.     cin >> str;
  71.     vi vc(str.length(), 0);
  72.  
  73.     int index = 0;
  74.     for (int i = 0; i < str.length(); i++) {
  75.         if (str[i] == '1') {
  76.             vc[index]++;
  77.         } else if (str[i] == '0' && str[i - 1] == '1') {
  78.             index++;
  79.         }
  80.     }
  81.     if (str[str.length() - 1] == '1') {
  82.         index++;
  83.     }
  84.     int len = str.length() - 1;
  85.     int flag = 1;
  86.  
  87.     int sum = 0;
  88.     for (int i = 0; i < index; i++) {
  89.         sort(vc.begin(), vc.end());
  90.         if (flag) {
  91.             sum += vc[len];
  92.             vc[len] = 0;
  93.             flag = 0;
  94.         } else {
  95.             vc[len] = 0;
  96.             flag = 1;
  97.         }
  98.     }
  99.     cout << sum << "\n";
  100. }
  101.  
  102. int main() {
  103. #ifdef Niloy
  104.     read("input.txt");  
  105.     write("output.txt");
  106. #endif
  107.     // fastInput;
  108.  
  109.     // solve();
  110.  
  111.     __test {
  112.         solve();
  113.     }
  114.    
  115.     showTime;
  116.     return 0;
  117. }
  118.  
  119.  
  120.  
RAW Paste Data