Codechef-JAIN Chef got Recipes

C
Problem NameChef got Recipes
JudgeCodechef
Problem Linkhttps://www.codechef.com/problems/JAIN
Algorithms & DSBitMasking
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define PB push_back #define VST(V) sort(V.begin(),V.end()) #define VSTrev(V) sort(V.begin(),V.end(),greater<long long int>()) #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); ll SET(ll NUM,ll POS) { return NUM | (1<<POS); } bool isOn(ll NUM,ll POS) { return (bool)(NUM & (1<<POS)); } ll dp[34]; map<char,ll>mp; int main() { //freopen("1input.txt","r",stdin); mp['a']=0; mp['e']=1; mp['i']=2; mp['o']=3; mp['u']=4; fast; ll tcase=1; cin>>tcase; for(ll test=1; test<=tcase; test++) { for(ll i=0; i<=32; i++) { dp[i]=0; } ll n; cin>>n; string s; vector<ll>V; for(ll i=0; i<n; i++) { cin>>s; ll siz=s.size(); ll mask=0; for(ll j=0; j<siz; j++) { ll val=mp[s[j]]; mask=SET(mask,val); } V.PB(mask); } VST(V); dp[V[n-1]]=1; ll ans=0; for(ll i=n-2; i>=0; i--) { for(ll j=0; j<=32; j++) { if((V[i]|j)==(1<<5)-1&&dp[j]>0) { ans+=dp[j]; } } dp[V[i]]++; } cout<<ans<<"\n"; } return 0; }
Code language: PHP (php)

About the author

Sheikh Arman Hossain
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

আবু রিফাত মুহাম্মদ

সখের বশে প্রোগ্রামিং করি। নতুন নতুন জিনিস শিখতে এবং শেখাতে ভালবাসি।

যোগাযোগ করুন

error: Alert: Content is protected !!