首页 > 其他分享 >Codeforces Round #739 (Div. 3) E

Codeforces Round #739 (Div. 3) E

时间:2022-10-28 18:12:00浏览次数:56  
标签:const string 删除 int Codeforces 序列 739 return Div

E. Polycarp and String Transformation

显然我们可以通过看谁消失的最早知道删除序列
然后有了删除序列以后 我们能干什么呢
显然对于每一个删除序列 我们要是第一次就把他删除了 那么那个字母就在原序列里只出现一倍
第二次把他删了 那么这第二个字母就出现了两倍
我们统计每个字母出现了多少次 然后再算出原串长度
注意这里不能有除不尽就cout-1
然后我们就可以线性的判断这个是否匹配了

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
vector<char>a;
string s;
string erase(string t,char i){
    string n;
    for(auto c:t)
        if(c!=i)n.push_back(c);
    return n;
}
void solve() {
    cin>>s;s=')'+s;
    vector<int>c(26);
    for(int i=1;i<s.size();i++){
        c[s[i]-'a']=i;
    }
    //shanchushunxu
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
    for(int i=0;i<26;i++)
        if(c[i])pq.push({c[i],i+'a'});
    a.clear();
    while(pq.size()){
        a.push_back(pq.top().second);
        pq.pop();
    }
    c.clear();
    c.resize(26);
    for(int i=1;i<s.size();i++)
        c[s[i]-'a']++;
    int len=0;
    for(int i=0;i<a.size();i++){
        len+=c[(a[i]-'a')]/(i+1);
        if(c[(a[i]-'a')]%(i+1)){cout<<-1<<endl;return;}
    }
    string t=s.substr(1,len);
    int now=1+len;
    for(auto i:a) {
        t=erase(t,i);
        string r=s.substr(now,t.size());
        if(r!=t){cout<<-1<<endl;return;}
        now+=t.size();
    }
    if(now!=s.size()){cout<<-1<<endl;return;}
    cout<<s.substr(1,len)<<' ';
    for(auto i:a)cout<<i;cout<<endl;
    return;
    cout<<-1<<endl;
}
signed main(){
    fast
    int t;t=1;cin>>t;
    while(t--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:const,string,删除,int,Codeforces,序列,739,return,Div
From: https://www.cnblogs.com/ycllz/p/16836986.html

相关文章

  • Codeforces Round #672 (Div. 2) D
    D.RescueNibel!转化题意就是叫我们求k条线段都有重合的方案数最开始想的是离散化+线段树手模拟一下样例这样会是有重复的我们要如何保证不重不漏!显然我们可以将线......
  • Codeforces Round #631 (Div. 1) - Thanks, Denis aramis Shitov! A
    A.DreamoonLikesColoring显然我们不看把整块涂满最优的构造就是1234....但是要考虑将整块板涂满我们就要往右挪显然我们每次挪后面的板子都会动我们一定要让......
  • 17.CF739C Alyona and towers 区间合并线段树
    17.CF739CAlyonaandtowers区间合并线段树给定序列,要求支持区间加,以及查询最长先增后减子区间(单峰序列)长度非常典型的区间合并线段树,记录左右起LIS,LCS,单峰洛谷传送门:......
  • 【PNR#2 Div1 D】找零(DP)(贪心)
    找零题目链接:PNR#2Div1D题目大意有500,100,50,10,5,1这些面额的纸币,你有X块钱,使用最少的纸币数表示的。然后有一些物品,每种只有一个,有费用。每次你可以选择一些......
  • Educational Codeforces Round 138 F Distance to the Path
    DistancetothePath思维+树链剖分首先与树链剖分无关,先考虑如果只更新一个点的情况因为更新一个点,它既能向根的方向更新,又能向子树方向更新,非常难维护,于是我们只......
  • D. Factorial Divisibility
    D.FactorialDivisibilityYouaregivenaninteger$x$andanarrayofintegers$a_1,a_2,\dots,a_n$.Youhavetodetermineifthenumber$a_1!+a_2!+\dots+a......
  • Codeforces Round #829 (Div. 2)-C1
    C1题目链接:https://codeforces.com/contest/1754/problem/C1emmm,不知道怎么说,做的时候考虑的问题是我通过什么方法来划分整个数组使得题意成立,后面又困在怎么判断是否存......
  • CF1690(Div3) E. Price Maximization 好题
    题目传送门首先,可以发现,我们不关心原数字的大小,只关心他们除以\(k\)之后的余数。如此考虑:两个数相加,\((a+b)/k=a/k+b/k+(a\)\(mod\)\(k+b\)\(mod\)......
  • Codeforces Round #707 (Div. 1, based on Moscow Open Olympiad in Informatics) A
    A.GoingHome观察ai<=2.5e6显然我们两数之和最多5e6我们开桶让后怎么暴力让我发愁了显然我们知道我们可能一个数被用了好多次这样显然不行可以想到就是把这个数对......
  • Codeforces Round #643 (Div. 2) C
    C.CountTriangles显然两边之和大于第三边我们可以先预处理出来这个两边之和我们暴力枚举x然后区间赋值[x+b,x+c]+1然后最后暴力枚举第三个边然后将大于第三边的方案......