1598A - Computer Game - CodeForces Solution


brute force dfs and similar dp implementation *800

Please click on ads to support us..

Python Code:

t = int(input())
for _ in range(t):
    grid = []
    col = int(input())
    r1 = list(input())
    r2 = list(input())
    a = 0
    while col > 0:
        if r1[0] == '0' and r2[0] == '0' or\
           r1[0] == '0' and r2[0] == '1' or\
           r1[0] == '1' and r2[0] == '0' :
            r1.remove(r1[0])
            r2.remove(r2[0])
            col -= 1
        elif r1[0] == '1' and r2[0] == '1':
            r1.remove(r1[0])
            r2.remove(r2[0])
            col -= 1
            a += 1
    if a == 0:
        print('YES')
    else:
        print('NO')
        

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define For(i, s, e) for (ll i = s; i < e; i++)
#define FOR(i, s, e) for (ll i = s; i <= e; i++)
#define FORD(i, s, e) for (ll i = s; i >= e; i--)
#define pb push_back
#define vii vector<ll>
#define makep make_pair
#define vpll vector<pair<ll, ll>>
#define fi first
#define se second
#define sii set<ll>
#define pii pair<int, int>
#define rev(c) reverse(c.begin(), c.end())
#define sortf(c) sort(c.begin(), c.end())
#define sortd(c) sort(c.begin(), c.end(), greater<int>())
#define test()   \
    int test;    \
    cin >> test; \
    while (test--)
#define fast()                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define sqr(n) (n) * (n)
#define len(s) (s.length())
#define re0 return 0
#define re return

ll const max2d = 1e4 + 7;
ll const N = 1e6 + 7;
ll const inf = 1e9 + 7;
char const nl = '\n';

// ! ¸,ø¤º°`°º¤ø,¸¸,ø¤º° [ нvмegy ] °º¤ø,¸¸,ø¤º°`°º¤ø,¸ roadтoнυe

signed main()
{
    fast();
    test()
    {
        int n; 
        cin >> n;
        char a[107], b[107]; 
        FOR(i, 1, n) { 
            cin >> a[i];
        }
        FOR(i, 1, n) { 
            cin >> b[i];
        }
        bool ck = true;
        FOR(i, 1, n) { 
            if (a[i] == '1' && b[i] == '1') ck = false;
        }
        cout << (ck ? "YES" : "NO") << nl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1302. Deepest Leaves Sum
1209. Remove All Adjacent Duplicates in String II
994. Rotting Oranges
983. Minimum Cost For Tickets
973. K Closest Points to Origin
969. Pancake Sorting
967. Numbers With Same Consecutive Differences
957. Prison Cells After N Days
946. Validate Stack Sequences
921. Minimum Add to Make Parentheses Valid
881. Boats to Save People
497. Random Point in Non-overlapping Rectangles
528. Random Pick with Weight
470. Implement Rand10() Using Rand7()
866. Prime Palindrome
1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST