Codeforces functionality may be limited from June 18, 19:00 (UTC) to June 19, 3:00 AM (UTC) due to technical maintenance. Polygon will work as usual. ×

sasanking's blog

By sasanking, 3 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;
        }
    }
}

Full text and comments »

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