475B - Strongly Connected City - CodeForces Solution


brute force dfs and similar graphs implementation *1400

Please click on ads to support us..

Python Code:

dimensions = input().split(' ')
n = int(dimensions[0])
m = int(dimensions[1])

dir_horiz = input()
dir_vert = input()

answer = True

if not (dir_horiz[0] == '<' or (dir_vert[0] == '^' and dir_vert[-1] == 'v' and '<' in dir_horiz)):
	answer = False
if not (dir_horiz[-1] == '>' or (dir_vert[0] == '^' and dir_vert[-1] == 'v' and '>' in dir_horiz)):
	answer = False
if not (dir_vert[0] == 'v' or (dir_horiz[0] == '>' and dir_horiz[-1] == '<' and 'v' in dir_vert)):
	answer = False
if not (dir_vert[-1] == '^' or (dir_horiz[0] == '>' and dir_horiz[-1] == '<' and '^' in dir_vert)):
	answer = False
	
if answer:
	print("YES")
else:
	print("NO")

C++ Code:

#include <bits/stdc++.h>
#include<cmath>
#include<algorithm>
#include <unordered_map>
#include<bitset>
#include <unordered_set>
#define Fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define sortvector(v) sort(v.begin(),v.end())
#define sortrvector(v) sort(v.rbegin(),v.rend())
#define loop(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
#define Checkk cerr<<".........."
typedef long long  ll;
const ll MOD = 1e9 + 7;
using namespace std;
const int N = 20+3;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
bool prime[N];
void Sieve()
{
    memset(prime, 1, sizeof(prime));
    prime[0] = prime[1] = false;
    for (int i = 2; i < N; i++) {
        if (prime[i]) {
            for (ll j = 1ll * i * i; j < N; j += i)
                prime[j] = false;
        }
    }
}
ll binaryexponentialpower(int base, int power)
{
    ll result = 1;
    while (power > 0) {
        if (power & 1)
            result *= base;
        base *= base;
        power /= 2;
    }
    return result;
}
ll modularbinaryexponentialpower(int base, int power, int mod)
{
    ll result = 1;
    while (power > 0) {
        if (power & 1)
            result = (result * base) % mod;

        base = ((base % mod) * (base % mod)) % mod;
        power /= 2;
    }
    return result;
}
ll __gcd(ll a, ll b) {
    while (b != 0)
    {
        ll a2 = a;
        a = b;
        b = a2 % b;
    }
    return a;
}
int GetDivisors(ll x) {
    set<int>s;
    for (ll i = 1; i * i <= x; i++) {
        if (x % i == 0)
        {
            s.insert(i);
            if (x / i != i)
            {
                s.insert(x / i);
            }
        }
    }
    return s.size();
}
int main() {

    Fast
        /*freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);*/
        int t = 1;
   // cin >> t;
    while (t--) {
        int n;
        cin >> n >> n;
        string s1; cin >> s1;
        string s2; cin >> s2;

        string s3 = { s1.front() , s1.back() , s2.front() , s2.back() };

        cout << (s3 == "<>v^" || s3 == "><^v" ? "YES" : "NO");

        
    }

}


Comments

Submit
0 Comments
More Questions

HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array
852. Peak Index in a Mountain Array
461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees
1450. Number of Students Doing Homework at a Given Time
700. Search in a Binary Search Tree
590. N-ary Tree Postorder Traversal
589. N-ary Tree Preorder Traversal
1299. Replace Elements with Greatest Element on Right Side
1768. Merge Strings Alternately
561. Array Partition I
1374. Generate a String With Characters That Have Odd Counts
1822. Sign of the Product of an Array
1464. Maximum Product of Two Elements in an Array
1323. Maximum 69 Number
832. Flipping an Image
1295. Find Numbers with Even Number of Digits