1722B - Colourblindness - CodeForces Solution


implementation

Please click on ads to support us..

Python Code:

def funt(arr,n):
    c=0
    for i in range(n):
        if arr[0][i]==arr[1][i] or (arr[0][i] == 'G' and arr[1][i] == 'B') or (arr[0][i] == 'B' and arr[1][i] == 'G'):
            c+=1
    return c==n
for _ in range(int(input())):
    n=int(input())
    l=[]
    for i in range(2):
        l.append(list(input()))
    if funt(l,n):
        print("YES")
    else:
        print("NO")

C++ Code:

#include<bits/stdc++.h>
using namespace std ;
#define  ll long long
#define ld long double
#define  LM10 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
/*
bool f = false;
int cnt = 0  ;
int partition (int arr[] , int l , int h)
{
    int p = arr[l] ;
    int i= l ;
    int j=h ;
    while(i<j)
    {
        do {
            {
                i++ ;
            }
        }while (arr[i]<=p) ;
        do {

                j-- ;

        }while(arr[j]>p) ;
        if(i<j)
        {
            swap(arr[i],arr[j]) ;
            f=true ;

        }
    }
    if (f)
        cnt++ ;
    swap(arr[l],arr[j]) ;
    return j ;
}
void quicksort (int arr[], int left , int right)
{

    if (left<right)
    {
        int piv = partition(arr , left ,right) ;
        quicksort(arr,left,piv) ;
        quicksort(arr,piv+1,right) ;
    }

}
*/


/*
int n , m , cnt  = 0  ;
ll s = 0 ,sum = 0 ;
void solve() {
    cin>>n>>m ;
    ll bytesComp [10004]={};
while(n--)
{
    int a , b ;
    cin>>a>>b ;
    s+=a;
    bytesComp[cnt] = a-b ;
    cnt++ ;
}
bool f = false ;
    sort(bytesComp , bytesComp+cnt) ;
    for (int i = 0; i < cnt; ++i) {
        cout<<bytesComp[i]<<' ';
    }
    cout<<"\n" ;

    for (int i = 0; i < cnt; ++i) {
        sum+= bytesComp[i] ;
        if (sum==s-m){
            cout<<i ;
            f=true ;
            break;
        }
    }
    if (f==false)
         cout<<-1 ;

}
*/

int n ;
bool f =true ;
void solve () {
    cin >> n;
    char arr[2][n];
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> arr[i][j];
            if (arr[i][j]=='G')
                arr[i][j]='B' ;
        }
    }


        for (int j = 0; j < n; ++j)
        {
            if (arr[0][j]!=arr[1][j])
            {
                f=false ;
                break;
            }

        }
    if (f)
        cout<<"YES\n" ;
    else
        cout<<"NO\n" ;

}

int main(void) {
    LM10
int tt ;
    cin>>tt ;
    while(tt--)
    {
        solve() ;
        f=true ;
    }

}




Comments

Submit
0 Comments
More Questions

97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
501A - Contest
160A- Twins
752. Open the Lock
1535A - Fair Playoff
1538F - Interesting Function
1920. Build Array from Permutation
494. Target Sum
797. All Paths From Source to Target
1547B - Alphabetical Strings
1550A - Find The Array
118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes
36. Valid Sudoku
557. Reverse Words in a String III
566. Reshape the Matrix
167. Two Sum II - Input array is sorted
387. First Unique Character in a String
383. Ransom Note
242. Valid Anagram
141. Linked List Cycle
21. Merge Two Sorted Lists
203. Remove Linked List Elements
733. Flood Fill