diff --git a/1272C - Yet Another Broken Keyboard.cpp b/1272C - Yet Another Broken Keyboard.cpp new file mode 100644 index 0000000..fcc093a --- /dev/null +++ b/1272C - Yet Another Broken Keyboard.cpp @@ -0,0 +1,75 @@ +//MD. HASNAIN ALI (UNSOLVED) +//I am nobody. + +#include +using namespace std; + +#pragma GCC optimize ("Ofast") +#pragma GCC optimize("O3") +#define ll long long +#define lo(i,a,n,x) for(i=a;i<=n;i=i+x) +#define loi(i,a,n,x) for(i=a;i>=n;i=i-x) +#define sca(n) scanf("%lld", &n) +#define pri(n) printf("%lld", n) +#define pb(a) push_back(a) +#define pop() pop_back() +#define mp make_pair +#define ff first +#define ss second +#define sqr(x) (x)*(x) +#define VI vector +#define SZ(a) (int)a.size() +#define SORT(x) sort(x.begin(), x.end()) +#define REV(x) reverse(x.begin(), x.end()) +#define UNIQUE(v) (v).erase(unique((v).begin(),(v).end()),(v).end()) +#define REV(x) reverse(x.begin(), x.end()) +#define all(x) x.begin(), x.end() +#define ODD(x) ((x)&1)==0?(0):(1) +#define TEST_CASE(t) for(int z=1;z<=t;z++) +#define distance(a,b) (sq(a.x-b.x) + sq(a.y-b.y)) +#define GCD(a, b) __gcd(a, b) +#define lcm(a, b) (a)*((b)/gcd(a,b)) +#define end0 "\n" +#define end1 cout<<"\n"; +#define pi acos(-1) +#define mod 1000000007 +#define inf 999999999999999999 +#define eps 10e-9 + + + + + + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0), cout.tie(0); + //freopen("input-2.txt","r",stdin); + //freopen("output-1.txt","w",stdout); + + ll i,j,a,b,p,s=0; + string x; + cin>>a>>b; + cin>>x; + char c; + int y[30]={0}; + lo(i,0,b-1,1){ + cin>>c; + y[c-'a']=1; + } + + p=0; + lo(i,0,a-1,1){ + if(y[x[i]-'a']==1) p++; + else{ + s+=((p*(p+1))/2); + p=0; + } + } + if(p) s+=((p*(p+1))/2); + + cout< +using namespace std; + +#pragma GCC optimize ("Ofast") +#pragma GCC optimize("O3") +#define ll long long +#define lo(i,a,n,x) for(i=a;i<=n;i=i+x) +#define sca(n) scanf("%lld", &n) +#define pri(n) printf("%lld", n) +#define SORT(x) sort(x.begin(), x.end()) +#define REV(x) reverse(x.begin(), x.end()) +#define all(x) x.begin(), x.end() +#define distance(a,b) (sq(a.x-b.x) + sq(a.y-b.y)) +#define end0 "\n" +#define end1 cout<<"\n"; +#define pi acos(-1) +#define mod 1000000007 +#define inf 999999999999999999 +#define eps 10e-9 + + + +int main() +{ + //ios::sync_with_stdio(0); + //cin.tie(0), cout.tie(0); + //freopen("test.txt","r",stdin); + + + ll t,i,j,l,a,b; + cin>>t; + string x; + lo(i,1,t,1) + { + cin>>l>>x; + a=0; + b=0; + lo(j,0,l-1,1){ + if(x[j]=='(') a++; + else a--; + if(a<0){ + b++; + a=0; + } + } + cout<