Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define asp ""
- #define aps ''
- #define one 1
- #define two 2
- #define dif !=
- typedef pair<int,int> ii;
- int main(){
- ios::sync_with_stdio(0);
- cin.tie(0);
- vector<set<ii>> Number(2600005); // 26x10^5
- vector<bool> ocup(2600005);
- string s;
- cin >> s;
- for(int i=0;i<2600005;i++) ocup[i] = false;
- priority_queue<int,vector<int>,greater<int>> pq;
- for(int i=0;i<s.size();i++){
- int valor = s[i] - 'a' + 1;
- Number[valor].insert({i,i}); // push nos ponteiros
- if(!ocup[valor]){
- pq.push(valor);
- ocup[valor] = true;
- }
- }
- int cont = 0;
- while(!pq.empty()){
- int valor = pq.top();
- pq.pop();
- cont++;
- for(auto &pointer: Number[valor]){
- int novo;
- if(pointer.first - 1 >= 0){
- novo = valor + s[pointer.first - 1] - 'a' + 1;
- Number[novo].insert({pointer.first - 1,pointer.second});
- if(!ocup[novo]){
- pq.push(novo);
- ocup[novo] = true;
- }
- }
- if(pointer.second + 1 < s.size()){
- novo = valor + s[pointer.second + 1] - 'a' + 1;
- Number[novo].insert({pointer.first,pointer.second + 1});
- if(!ocup[novo]){
- pq.push(novo);
- ocup[novo] = true;
- }
- }
- }
- }
- cout << cont << endl;
- }
- // abbab
- // adbbabdcdbcbacdabbaccdac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement