Suiiinaldo's blog

By Suiiinaldo, history, 6 months ago, In English

I am getting WA at Pretest 2 and the token which is differentiated is 252. I don't know if there is any corner cases, because it is passed at edge case like substring length = 7.Please help. The problem link is attached below 1605C - Dominant Character

My submission is stated below: 231633540


#include<bits/stdc++.h> #define upper(s) transform(s.begin(),s.end(),s.begin(),::toupper) #define lower(s) transform(s.begin(),s.end(),s.begin(),::tolower) #define all(s) s.begin(),s.end() #define rep(n) for(int i=0;i<n;i++) #define repn(i,a,b) for(int i =a;i<b;i++) #define showvec(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl #define showmap(m) for(auto i=m.begin();i!=m.end();++i) cout<<i->first<<" "<<i->second<<endl; #define showset(s) for(auto i=s.begin();i!=s.end();++i) cout<<*i<<" ";cout<<endl; #define ll long long #define endl '\n' #define int long long #define pii pair<int,int> using namespace std; //x<<y is x*(2^y) //x>>y is x/(2^y) void solve() { int n; cin>>n; string s; cin>>s; int mini = INT_MAX; vector<int> aIndex; vector<int> bOccur(n); vector<int> cOccur(n); bOccur[0] = s[0] == 'b' ? 1 : 0; cOccur[0] = s[0] == 'c' ? 1 : 0; for(int i = 0;i<n;i++) { if(s[i] == 'a') aIndex.push_back(i); } for(int i = 1;i<n;i++) { bOccur[i] = (s[i] == 'b') ? bOccur[i-1]+1 : bOccur[i-1]; cOccur[i] = (s[i] == 'c') ? cOccur[i-1]+1 : cOccur[i-1]; } if(aIndex.size() <= 1) { cout<<"-1\n"; return; } int low = 0,high = 1; n = aIndex.size(); while(low < high and high < n) { if(bOccur[aIndex[high]] - bOccur[aIndex[low]] >= high - low + 1 or cOccur[aIndex[high]] - cOccur[aIndex[low]] >= high - low + 1) { high++; } else { mini = min(mini,aIndex[high] - aIndex[low] + 1); low = high; high += 1; } } if(mini == INT_MAX) cout<<"-1\n"; else cout<<mini<<endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int t; cin>>t; while(t-->0) { solve(); } return 0; }

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Suiiinaldo, history, 8 months ago, In English

1866C - Completely Searching for Inversions

What is leading my solution to go memory limit exceeded? Please Help. And Can Anybody give hint about the correct approach. I am going with the complete brute force approach of calculating the Z Array and then finding the number of inversion in linear time. I was calculating the Z Array according to the given question.

My Submissions are as follows: 221686347 221686896

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Suiiinaldo, history, 20 months ago, In English

Hey everyone, I wanted to ask one thing that when I iterate through an array and comparing something like ar[i] and ar[i+1] and if I do this in my VSCode and iterating till i<n (which is obviously not possible) but it runs completely fine on my VSCode and doesn't give an error while running it on Codeforces generally the program goes into pretests passed condition and gets rejected in checking phase. Please help because this costed me a very easy problem in the contest.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Suiiinaldo, history, 20 months ago, In English

Question Link:

1726C - Jatayu's Balanced Bracket Sequence

Here is my Code :

#include<bits/stdc++.h>
#define upper(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define lower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define all(s) s.begin(),s.end()
#define rep(m) for(int i=0;i<n;i++)
#define showvec(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define showmap(m) for(auto i=m.begin();i!=m.end();++i) cout<<i->first<<" "<<i->second<<endl;
#define ll long long
#define endl '\n'
using namespace std;
void dfs(int node,vector<vector<int>> &adj,vector<int> &vis)
{
    vis[node] = 1;
    for(auto it : adj[node])
    {
        if(!vis[node])
        {
            dfs(it,adj,vis);
        }
    }
}
void solve()
{
    string s;
    cin>>s;
    int n=s.length();
    stack<pair<char,int>> st;
    vector<vector<int>> adj;
    for(int i=0;i<n;i++)
    {
        if(s[i]==')')
        {
            if(st.top().first =='(')
            {
                adj[st.top().second].push_back(i);
                adj[i].push_back(st.top().second);
                st.pop();
            }
        }
        else
        st.push({s[i],i});
    }
    if(s[0] == '(' and s[n-1]==')')
    {
        adj[0].push_back(n-1);
        adj[n-1].push_back(0);
    }
    vector<int> vis(n,0);
    int start = 0;
    int count = 0;
    for(int i=0;i<vis.size();i++)
    {
        if(!vis[i])
        {
            dfs(start,adj,vis);
            count++;
        }
    }
    cout<<count<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int t;
    cin>>t;
    while(t-->0)
    {
        solve();
    }
    return 0;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Suiiinaldo, history, 22 months ago, In English

Question Link:

1692D - The Clock

Here is my code:

#include<bits/stdc++.h>
#define upper(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define lower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define all(s) s.begin(),s.end()
#define rep(m) for(int i=0;i<n;i++)
#define showvec(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define showmap(m) for(auto i=m.begin();i!=m.end();++i) cout<<i->first<<" "<<i->second<<endl;
#define ll long long
using namespace std;
bool CheckPalindrome(string a,string b)
{
    reverse(all(a));
    if(a==b)
    return true;
    else
    return false;
}
void solve()
{
    string FullTime;
    cin>>FullTime;
    ll AddedTime;
    cin>>AddedTime;
    int InitialHour=stoi(FullTime.substr(0,2));
    int InitialMinute=stoi(FullTime.substr(3,4));
    string HoursFirstCheck=to_string(InitialHour);
    string MinutesFirstCheck=to_string(InitialMinute);
    int UpdatedHour=InitialHour;int UpdatedMinute=InitialMinute;int counter=0;
    if(CheckPalindrome(HoursFirstCheck,MinutesFirstCheck))
    counter++;
    do
    {
        UpdatedHour+=AddedTime/60;
        if(UpdatedHour>23)
            UpdatedHour=UpdatedHour-24;
        UpdatedMinute+=AddedTime%60;
        if(UpdatedMinute>60)
        {
            UpdatedMinute-=60;
            UpdatedHour+=1;
        }
        string MinutesFormat=to_string(UpdatedMinute);
        string HoursFormat=to_string(UpdatedHour);
        if(UpdatedHour<10)
        {
            HoursFormat="0"+HoursFormat;
        }
        if(UpdatedMinute<10)
        {
            MinutesFormat="0"+MinutesFormat;
        }
        cout<<HoursFormat<<"   "<<MinutesFormat<<endl;
        if(CheckPalindrome(HoursFormat,MinutesFormat))
        counter++;
    }while(UpdatedHour!=InitialHour and UpdatedMinute!=InitialMinute);
    cout<<counter<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int t;
    cin>>t;
    while(t-->0)
    {
        solve();
    }
    return 0;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it