r0n1n's blog

By r0n1n, history, 6 years ago, In English

Hi Codeforces community!

I'm just reaching out to see if anyone could help me with the 266C Below the diagonal question . I am getting Run time error for the tenth test case where the value of n is 500.

My code link is (http://ideone.com/9mqDlp)

Thanks in advance.

Full text and comments »

  • Vote: I like it
  • -6
  • Vote: I do not like it

By r0n1n, history, 6 years ago, In English

I am facing run time error . The error comes for the test case 2 33 1 1 1 1 1 1 1 1 1

In my code when I am comparing the value of the element in the string and the value at the index of the array.53606476 //MEHNAT

include<bits/stdc++.h>

using namespace std;

define tr(c, it) \

for(auto it = c.begin(); it != c.end(); it++)

define ll long long

//const int MAX=1e3 + 5;

bool flag=0;

int main(){ int n; string s=""; cin>>n>>s; int a[n]; for(int i=1;i<10;i++){ cin>>a[i]; }

stack <pair<int,int> > st;

pair <int,int> p;
p.first=0;
p.second=0;
int b;
for(int i=n-1;i>=0;i--){
    b=((int) s[i]) - 48;
    if(b<a[b] && !flag){     //Facing the error here for a[b].
        p.second=i;
        flag=1;
    }
    if(b>=a[b] && flag){
        p.first=i+1;
        st.push(p);
        flag=0;
    }
    if(b<a[b] && flag && i==0){
        p.first=0;
        st.push(p);
        flag=0;
    }
}

/*
for(int i=0;st.size();i++){
    q=st.top();
    st.pop();
    cout<<q.first<<" "<<q.second<<endl;
}*/

if(st.empty()){
    cout<<s;
}
else{
    pair <int,int> q;
    q=st.top();
    for(int i=q.first;i<=q.second;i++){
        int b=((int) s[i]) - 48;
        s[i]=a[b] + 48;
    }
    cout<<s;
}


return 0;

}

/* check for corner cases(n == 1?) see the constraint read the highlighted text again */

Full text and comments »

  • Vote: I like it
  • -21
  • Vote: I do not like it