D题通过率98.04%,求hack数据!!!

#include<bits/stdc++.h>
#include<bits/extc++.h>
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
#define all(x) (x).begin(),(x).end()
#define quchong(x) (x).erase(unique(all(x)),(x).end())
#define Yes(x,y) cout<<((x)?"Yes":"No")<<y
#define yes(x,y) cout<<((x)?"yes":"no")<<y
#define YES(x,y) cout<<((x)?"YES":"NO")<<y
#define ls ((u)<<1)
#define rs ((u)<<1|1)
#define mid (((l)+(r))>>1)
#define lowbit(x) ((x)&(-(x)))
#define itn int
#define asn ans
#define reisze resize
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pii pair<int,int>
#define tll tuple<LL,LL,LL>
#define tii tuple<int,int,int>
#define plll pair<LLL,LLL>
#define ULL unsigned long long
#define LL long long
#define LLL __int128
#define ld long double
#define ui64 uint64_t
#define ui32 uint32_t
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using RBTree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
T fang(const T& a){
    return a*a;
}
template<typename T,typename Q>
bool chmax(T& u1,T& u2,const Q& v){
    if(v>u1) { u2 = u1, u1 = v;return true;}
    if(v>u2){u2=v;return true;}
    return false;
}
template<typename T,typename Q>
bool chmin(T& u1,T& u2,const Q& v){
    if(v<u1) { u2 = u1, u1 = v;return true;}
    if(v<u2){u2=v;return true;}
    return false;
}
template<typename T,typename Q>
bool chmin(T& a,const Q& b){
    return a > b && (a = b, true);
}
template<typename T,typename Q>
bool chmax(T& a,const Q& b){
    return a<b&&(a=b,true);
}
template<typename t1,typename t2>
istream& operator>>(istream& in,pair<t1,t2>& pa){
    in>>pa.first>>pa.second;
    return in;
}
template<typename t1,typename t2>
ostream& operator<<(ostream& out,const pair<t1,t2>& pa){
    out<<pa.first<<' '<<pa.second;
    return out;
}
template<typename T>
istream& operator>>(istream& in,vector<T>& arr){
    for(auto& v:arr)in>>v;
    return in;
}
template<typename T>
ostream& operator<<(ostream& out,const vector<T>& arr){
    for(auto& v:arr)out<<v<<' ';
    return out;
}
int rand(int l,int r){
    static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<int>(l, r)(rng);
}
const ld eps=1e-9;
const int NN=2e6+5;
const int SIZ=1e7;
const LL inf=1e17;
void solve(){

}
signed main(){
    IOS;
    string s;
    cin>>s;
    if(s.size()%2){
        int n=s.size()+1;
        n/=2;
        for(int i=0;i<n;i++){
            if(i%2)cout<<"00";
            else cout<<"11";
        }
        return 0;
    }
    int n=s.size();
    int pre=-1;
    bool cs=false;
    for(int i=0;i<n-1;i++){
        if(i%2==0&&s[i]!=s[i+1]||i%2==1&&s[i]==s[i+1]){
            pre=i;
            cs=(i%2==0);
            break;
        }
    }
    if(pre==-1){
        cout<<s;
        return 0;
    }
    if(cs){
        assert(s[pre+1]!=s[pre]);
        if(s[pre+1]>s[pre]) { s[pre + 1] = s[pre] = s[pre] + 1;
            if(pre>0&&s[pre]==s[pre-1]){
                string t;
                for(int i=0;i<pre;i+=2){
                    t.push_back(s[i]-'0');
                }
                reverse(all(t));
                int cc=1;
                for(char& c:t){
                    c+=cc;
                    cc=c/10;
                    c%=10;
                }
                if(cc)t.push_back(cc);
                for(char& c:t)c+='0';
                for(int p=t.size()-1;p>0;p--){
                    if(t[p]==t[p-1]){
                        if(t[p-1]!='9'){
                            t[p-1]++;
                            for(int k=p-2;k>=0;k--){
                                t[k]=t[k+1]=='0'?'1':'0';
                            }
                        }else{
                            int pu=-10;
                            int g=p+1;
                            for(;g+1<t.size();g+=2){
                                if(!(t[g]=='8'&&t[g+1]=='9')){
                                    assert(t[g]!='9');
                                    t[g]++;
                                    if(t[g]==t[g+1])t[g]++;
                                    pu=g-1;
                                    break;
                                }
                            }
                            if(pu==-10){
                                if(g<t.size())t[g]++;
                                else t.push_back('1');
                                pu=t.size()-2;
                            }
                            for(int j=pu;j>=0;j--)t[j]=(t[j+1]=='0'?'1':'0');
                        }
                        break;
                    }
                }
                reverse(all(t));
                for(char c:t)cout<<c<<c;
                char la=t.back();
                for(int i=pre;i<n;i+=2){
                    char ne=la=='0'?'1':'0';
                    cout<<ne<<ne;
                    la=ne;
                }
                return 0;
            }
        }
        else s[pre+1]=s[pre];
        pre++;}
    else{
        assert(s[pre+1]==s[pre]);
        if(s[pre+1]=='9'){
            string t;
            for(int i=0;i<pre;i+=2){
                t.push_back(s[i]-'0');
            }
            reverse(all(t));
            int cc=1;
            for(char& c:t){
                c+=cc;
                cc=c/10;
                c%=10;
            }
            if(cc)t.push_back(cc);
            for(char& c:t)c+='0';
            for(int p=t.size()-1;p>0;p--){
                if(t[p]==t[p-1]){
                    if(t[p-1]!='9'){
                        t[p-1]++;
                        for(int k=p-2;k>=0;k--){
                            t[k]=t[k+1]=='0'?'1':'0';
                        }
                    }else{
                        int pu=-10;
                        int g=p+1;
                        for(;g+1<t.size();g+=2){
                            if(!(t[g]=='8'&&t[g+1]=='9')){
                                assert(t[g]!='9');
                                t[g]++;
                                if(t[g]==t[g+1])t[g]++;
                                pu=g-1;
                                break;
                            }
                        }
                        if(pu==-10){
                            if(g<t.size())t[g]++;
                            else t.push_back('1');
                            pu=t.size()-2;
                        }
                        for(int j=pu;j>=0;j--)t[j]=(t[j+1]=='0'?'1':'0');
                    }
                    break;
                }
            }
            reverse(all(t));
            for(char c:t)cout<<c<<c;
            char la=t.back();
            for(int i=pre+1;i<n;i+=2){
                char ne=la=='0'?'1':'0';
                cout<<ne<<ne;
                la=ne;
            }
            return 0;
        }else{
            s[pre+1]=s[pre]+1;
            s[pre+2]=s[pre+1];
            pre+=2;
        }
    }
    for(int i=pre+1;i<n;i+=2){
        char c=s[i-1]=='0'?'1':'0';
        s[i]=s[i+1]=c;
    }
    cout<<s;
    return 0;
}

全部评论
输入:3323333333333333 你的输出:4400110011001100
点赞 回复 分享
发布于 01-09 11:42 浙江
98.04%+1
点赞 回复 分享
发布于 01-09 00:41 山东

相关推荐

脑子烧了,这是什么规律啊。1,10,19,37,64,(&nbsp;)
hl7:0*9+1 1*9+1 2*9+1 4*9+1 7*9+1,9的系数是前两个系数相加再加1?
投递美团等公司10个岗位
点赞 评论 收藏
分享
07-07 17:06
已编辑
深圳技术大学 golang
您好请问贵司招切图仔...:b站的录用通知好中二
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务