sasanking's blog

By sasanking, 2 months ago, In English

This is the question I am talking about — 1948 C : Arrow Path I have written an easier solution only using if and while loop. Check this out if someone is stuck at this question

**HERE WE GO**

#include <vector>
using namespace std;

int main(){
    int t;
    char temp;
    int take;
    cin>>t;
    for(int test=0;test<t;test++){
        int n;
        cin>>n;

        string row1;
        cin>>row1;
        string row2;
        cin>>row2;
        
        int i=0;
        int row=1;
        int nmove=0;
        int flag=true;
        do{
            if(row==1){
                if(row1[i+1]=='<'){
                    if(row2[i]=='<'){
                        //cout<<i<<endl;
                        cout<<"NO"<<endl;
                        flag = false;
                        break;
                    }
                    row = 2;
                    i=i+1;
                    nmove++;
                }
                else{
                    i=i+2;
                    nmove=0;
                }
            }
            else{
                if(row2[i+1]=='<'&&i!=n-2){
                    if(row1[i]=='<'){
                        //cout<<i<<endl;
                        cout<<"NO"<<endl;
                        flag = false;
                        break;
                    }
                    row = 1;
                    i=i+1;
                    nmove++;
                }
                else{
                    i=i+2;
                    nmove=0;
                }
            }
            if(nmove>=2){
                //cout<<i<<endl;
                cout<<"NO"<<endl;
                flag = false;
                break;
            }
        }while(i<=n-2);
        if(flag){
            cout<<"YES"<<endl;
        }
    }
}
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it
look only if you tried hard finding mistake in you sol
  • »
    »
    7 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Sorry for that, I misunderstood the question. I have got it cleared and updated the blog.

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

Even I did it easily.I guess our approach is similar just that you wrote a bit too much code

void solve(){ int n; cin>>n; string s1,s2; cin>>s1>>s2;

bool check=false;
for (int  i = 1; i < n; i+=2)
{
    if((s1[i]=='<'&&s2[i-1]=='<')||s1[i]=='<'&&s2[i+1]=='<'){cout<<"NO"<<endl;return;}
}
cout<<"YES"<<endl;

}