Codeforces Round #402 (Div. 2) D. String Game[二分]

链接:传送门

题意:有p,t两个字符串,现在有p.size()次操作,问最多能执行多少次操作,使得t仍旧是p的子序列.一开始t一定是p的子序列

思路:二分check

#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
#define debug puts
using namespace std;
typedef long long ll;

const int N=2e5+5;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
string p,t;
int a[N],sz;

bool check(int st){
    vector<int> vec;
    for(int i=st;i<sz;i++)  vec.pb(a[i]-1);
    sort(vec.begin(),vec.end());
    string tt="";
    for(auto i:vec) tt+=p[i];
//    cout << tt << endl;
    int i,j;
    for(i=0,j=0;i<(int)tt.size();i++){
        if(j<(int)t.size()&&tt[i]==t[j])    j++;
    }
    return j==(int)t.size();
}

int main(void){
    cin >> p >> t;
    sz=(int)p.size();
    for(int i=0;i<sz;i++)  scanf("%d",&a[i]);
    int l=0,r=sz-1,ans;
    while(l<=r){
        int mid=l+r>>1;
//        cout <<"mid="<<mid<<" ";
        if(check(mid))  l=mid+1,ans=mid;
        else    r=mid-1;
    }
    cout << ans << endl;

    return 0;
}
void bef0re_submit(){
    debug("Make sure the algorithm is right!");
    debug("LONG LONG!!!");
    debug("Check n and m are misuesd???");
    debug("Make sure output format is right/// Yes??YES  (%.20LF)???");
    debug("if all meet,run with special situation!!!");
    debug("I confirm that I have done all above");
}


/*********
4 5
0 3 8 4
*********/

全部评论

相关推荐

感觉他们一点都不了解现在这个社会就业有多难,已经在牛客刷到好多篇&nbsp;延毕的帖子了,延毕就会导致已经找好的工作就没了,还得重新再找,学校和老师们是怎么想的呢????看到学生丢失工作会开心吗&nbsp;就业数据都在造假,真实的就业困难不去解决&nbsp;一个个真是好样的
从今天开始狠狠卷JVAV_癫:学生看到的是导师不放实习导致offer黄了。 导师看到的是招进来的学生吃自己补助和自己的招生名额,却没给自己升迁带来任何帮助,还要跑路。 根本利益的不一致,最主要留校的导师大概率是职场上招聘失败的,被迫留校的,什么牛鬼蛇神都会有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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