387C - George and Number - CodeForces Solution


greedy implementation *1700

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
int mod=1e9+7;
#define pb push_back
#define umii unordered_map<int,int>
#define umci unordered_map<char,int>
#define umcc unordered_map<char,char>
#define mii map<int,int>
#define mci map<char,int>
#define mcc map<char,char>
#define vi vector<int>
#define vvi vector<vector<int>>
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

int power(int x,int y){
    int value = 0;
    if(y<0) return 0;
    else if(y==0) return 1;
    else if(y==1) return x;
    else if(y%2) value = (x*(power((x*x)%mod,y/2)%mod))%mod;
    else value = power((x*x)%mod,y/2)%mod;
    return value%mod;
}


int inversemod(int x) {
    return power(x,mod-2)%mod;
}


void pp(int k){
    if(k==0)
    cout<<"NO"<<endl;
    else if(k==-1)
    cout<<-1<<endl;
    else
    cout<<"YES"<<endl;
}


int32_t main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int tt;
    tt=1;
    // cin>>tt;
    while(tt--){
        string s;
        cin>>s;
        int n=s.size();
        vector<string>v;
        string p;
        for(int i=0;i<s.size();i++){
            if(s[i]=='0'){
                p+="0";
            }
            else{
                v.pb(p);
                p="";
                p+=char(s[i]);
            }
        }
        v.pb(p);
        int idx=1;
        p=v[0];
        for(int i=1;i<v.size();i++){
            if(p.size()<v[i].size()){
                idx=i+1;
            }
            else if(p.size()==v[i].size()){
                if(v[i][0]>p[0]){
                    idx=i+1;
                }
            }
            p+=v[i];
        }
        cout<<v.size()-idx+1<<endl;
    }
	// your code goes here
	return 0;
}
/**/


Comments

Submit
0 Comments
More Questions

53. Maximum Subarray
1527A. And Then There Were K
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers
318. Maximum Product of Word Lengths
448. Find All Numbers Disappeared in an Array
1155. Number of Dice Rolls With Target Sum
415. Add Strings
22. Generate Parentheses
13. Roman to Integer
2. Add Two Numbers
515. Find Largest Value in Each Tree Row
345. Reverse Vowels of a String
628. Maximum Product of Three Numbers
1526A - Mean Inequality
1526B - I Hate 1111
1881. Maximum Value after Insertion
237. Delete Node in a Linked List
27. Remove Element
39. Combination Sum
378. Kth Smallest Element in a Sorted Matrix
162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island
402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum