bitmasks dp *2200

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define e "\n"
#define ll long long
#define all(v) v.begin(),v.end()

void fast() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin),
            freopen("output.txt", "w", stdout);
#endif
}

const ll mod = 1e9+7 , N = 3e5+2, M = 2e3+2;
int t,id;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

ll gcd(ll a, ll b) { return (!b) ? a : gcd(b, a % b); }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int freq[1 << 20];
void solve() {
    string s;
    cin >> s;
    int curr;
    for (int i = 0; i < s.size(); ++i) {
        curr = 0;
        for (int j = i; j < s.size(); ++j) {
            if (curr & (1 << (s[j] - 'a')))break;
            curr |= (1 << (s[j] - 'a'));
            freq[curr] = (j - i) + 1;
        }
    }
    // 2e7
    int ans=1;
    for (int i = 0; i < 1<<20; ++i)
        for (int j = 0; j < 20; ++j)if ((1 << j) & i)
        {
            freq[i]= max(freq[i], freq[i^(1<<j)]);
        }
    int mx=0;
    for (int i = 0; i < 1<<20; ++i) {
        int cpy=(1<<20)-1-i;
       mx= max(mx,freq[i]+freq[cpy]);
    }
  //  cout<<freq[((1<<20)-1)|(1<<('f'-'a'))]<<e;

    cout<<mx;

}
int main() {
    fast();
    t = 1,id=1;
    //cin >> t ;
    while (t--)
        solve(),++id;


}







Comments

Submit
0 Comments
More Questions

478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft
1418A - Buying Torches
131C - The World is a Theatre
1696A - NIT orz